60分代码,求改正
查看原帖
60分代码,求改正
263701
2008shitou楼主2021/5/4 10:13
#include<bits/stdc++.h>
using namespace std;
int main(){
char a[100000];
cin.getline(a,100000);
stack<char>  x;
for(int i=0;i<strlen(a)-1;i++){
	if(a[i]=='('){
		x.push(')');
	}else{
		if(x.size()!=0){
			if(a[i]==x.top()){
				x.pop();
			}else{
				cout<<"NO";
				return 0;
			}		
		}else{
			cout<<"NO";
			return 0;
		}
	}	
}
if(x.size()==0){
		cout<<"YES";
	}else{
		cout<<"NO";
		
	}
	return 0;
}

2021/5/4 10:13
加载中...