/*
简单的栈操作
*/
#include <cstdio>
#include <cstring>
#include <cctype>
#include <algorithm>
using namespace std;
const int MAXN = 134;
char st[MAXN];
int main() {
#ifndef ONLINE_JUDGE
freopen("in.txt", "r", stdin);
#endif
int T;
scanf("%d\n", &T);
while(T--) {
char c;
int ok = 1;
int fr = 0;
while((c = getchar()) != '\n') {
if(ok) {
switch(c) {
case '(': case '[':
st[fr++] = c;
break;
case ')':
if(st[fr-1] != '(') {
ok = 0;
} else {
--fr;
}
break;
case ']':
if(st[fr-1] != '[') {
ok = 0;
} else {
--fr;
}
break;
}
}
}
if(ok && !fr) printf("Yes\n");
else printf("No\n");
}
return 0;
}
UVa 673 - Parentheses Balance
最新推荐文章于 2024-02-11 21:51:50 发布