#define _CRT_SECURE_NO_WARNINGS 1#include<iostream>#include<cstdio>#include<fstream>#include<algorithm>#include<cmath>#include<deque>#include<vector>#include<queue>#include<string>#include<cstring>#include<map>#include<stack>#include<set>usingnamespacestd;
string a;
stack<int> q;
intmain(){
int flag = 1, i, j;
char t;
while (getline(cin, a))
{
for (int i = 0; i < a.size(); i++)
{
if (a[i] == '(' || a[i] == '[' || a[i] == '{')
q.push(a[i]);
elseif (a[i] == ')' || a[i] == ']' || a[i] == '}')
{
if (a[i] == ')') t = '(';
elseif (a[i] == ']') t = '[';
elseif (a[i] == '}') t = '{';
if (q.size()!=0&&q.top() == t)
{
q.pop();
}
else
{
flag = 0;
break;
}
}
}
if (q.size() != 0)
flag = 0;
if (flag == 0) cout << "no" << endl;
elseif (flag == 1) cout << "yes" << endl;
while (q.size()) q.pop();
flag = 1;
}
return0;
}
sdut括号匹配
最新推荐文章于 2024-05-13 14:11:50 发布