#include <iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<math.h>
#include<sstream>
using namespace std;
#define L 101
int top=0; //仿栈
char a;
bool flag = true;
int main()
{
int i=0;
//用a[i]大小的必然性(1个char)来限制输入大小
cin >> a;
while(a!='@'){
if(a == '(') top++;
if(a == ')'){
if(top==0){
cout << "NO";
flag = false;
break;
}else{top--;}
}
cin >> a;
}
if(top>0 && flag){cout << "NO";} //罗生门思想
else if(flag){cout << "YES";}
return 0;
}
//cout << "输入:"
练习1 - 表达式括号匹配(stack)
最新推荐文章于 2023-08-16 22:54:55 发布