32分代码求调
  • 板块P1241 括号序列
  • 楼主__why
  • 当前回复1
  • 已保存回复1
  • 发布时间2023/12/15 20:12
  • 上次更新2023/12/15 22:00:32
查看原帖
32分代码求调
768270
__why楼主2023/12/15 20:12

啊啊啊?为啥调完后从44分到32分了QAQ

#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e3+5;
int top = 0,a[maxn];
void check(){
	if(top!=0){
		if(a[top-1]==1)cout<<')';
		else cout<<']';
		top--;
	}
}
int main(){
	char c;
	while(cin>>c){
		if(c=='('){
			check();
			a[top++] = 1;
			cout<<c;
		}else if(c==')'){
			if(a[top-1]==2){
				cout<<']';
				top--;
			}
			if(a[top-1]!=1){
				cout<<'(';
			}else{
				top--;
			}
			cout<<c;
		}else if(c=='['){
			check();
			if(top!=0){
				if(a[top-1]==1)cout<<')';
				else cout<<']';
				top--;
			}
			a[top++] = 2;
			cout<<c;
		}else{
			if(a[top-1]==1){
				cout<<')';
				top--;
			}
			if(a[top-1]!=2){
				cout<<'[';
			}else{
				top--;
			}
			cout<<c;
		}
	}

}

44分:

#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e3+5;
int a[maxn];
int main(){
	char c;
	int top = 0;
	while(cin>>c){
		if(c=='('){
			a[top++] = 1;
			cout<<c;
		}else if(c==')'){
			if(a[top-1]!=1){
				cout<<'(';
			}else{
				top--;
			}
			cout<<c;
		}else if(c=='['){
			a[top++] = 2;
			cout<<c;
		}else{
			if(a[top-1]!=2){
				cout<<'[';
			}else{
				top--;
			}
			cout<<c;
		}
	}
}
2023/12/15 20:12
加载中...