样例能过,但WA,排版问题还请见谅
查看原帖
样例能过,但WA,排版问题还请见谅
799434
HitLixinhao楼主2022/12/26 10:35
#include<iostream>
#include<cstdio>
#include<stack>
#define maxn 130
using namespace std;

int main(){
int n,flag=1;
cin>>n;
getchar();
char tmp[maxn];
stack<char>s;
while(n--){
	flag=1;
	while(!s.empty()) s.pop(); 
	gets(tmp); 
	for(int i=0;tmp[i]!='\0';i++){
		if(tmp[i]=='['||tmp[i]=='(') 
        		s.push(tmp[i]);
		if(tmp[i]==']'){
		if(!s.empty()&&s.top()=='[') 
        		s.pop();
		else {
			cout<<"No"<<"\n";
			flag=0;
			break;
		}
		}
	if(tmp[i]==')'){
		if(!s.empty()&&s.top()=='(') 
          		s.pop();
		else {
			cout<<"No"<<"\n";
			flag=0;
			break;
		}
	} 
	}
	if(flag){
	if(s.empty())cout<<"Yes"<<"\n";
		}
	}
}
2022/12/26 10:35
加载中...