UKE求助
查看原帖
UKE求助
637180
ChrisWangZi楼主2023/1/6 13:44

前几天交了一个WA,今天调好了就是UKE

代码求调(UKE):

#include<iostream>
#include<stack>
using namespace std;
int main(){
	int T;
	cin>>T;
	getchar();
	while(T--){
	    string a;
	    getline(cin,a);
	    stack<char> s;
	    bool isp=false;
	    for(int i=0;i<a.length();i++){
	    	if(a[i]=='('||a[i]=='['){
	    		s.push(a[i]);
			} 
			else{
				if(s.empty()){
					cout<<"NO\n";
					isp=true;
					break;
				}
				if((s.top()=='('&&a[i]==']')||(s.top()=='['&&a[i]==')')){
					cout<<"NO\n";
					isp=true;
					break;
				}
				s.pop();
			}
		}
		if(isp){
			continue;
		}
		if(!s.empty()){
			cout<<"NO\n";
		}
		else{
			cout<<"YES\n";
		}
	}
    return 0;
}
2023/1/6 13:44
加载中...