```c
#include<bits/stdc++.h>
using namespace std;
char a[256];
int n;
stack<char>s;
int main()
{
scanf("%s",a);
n=strlen(a);
for(int i=0;i<n-1;i++){
if(a[i]=='(') s.push(a[i]);
else if(a[i]==')'){
if(s.size()>0) s.pop();
//因为栈已经空了还去查询s.top()
//所以你原来的代码炸了
else
{
printf("NO");
return 0;
}
}
}
if(!s.empty()){
printf("NO");
return 0;
}
else{
printf("YES");
return 0;
}
}
```
有用拜托给个关注
@[eastonwu](/user/792928)
by ive_wonyoung @ 2024-03-07 13:52:58
@[ive_wonyoung](/user/1043012) 可以了,谢谢大佬,已关
by eastonwu @ 2024-03-08 12:47:31