-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path673.cpp
More file actions
36 lines (36 loc) · 873 Bytes
/
673.cpp
File metadata and controls
36 lines (36 loc) · 873 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#include <bits/stdc++.h>
using namespace std;
int main() {
stack<char> s;
char a[500];
int tc;
cin >> tc;
getchar();
while (tc--) {
gets(a);
int l = strlen(a);
while (s.size()) s.pop();
int flag = 0;
for (int i = 0; i < l; i++) {
if (a[i] == '(' || a[i] == '[')
s.push(a[i]);
else if (a[i] == ')') {
if (s.size() && s.top() == '(')
s.pop();
else
flag = 1;
} else if (a[i] == ']') {
if (s.size() && s.top() == '[')
s.pop();
else
flag = 1;
}
if (flag) break;
}
if (flag || s.size())
printf("No\n");
else
printf("Yes\n");
}
return 0;
}