-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathP673.cpp
51 lines (47 loc) · 881 Bytes
/
P673.cpp
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include <iostream>
#include <ctype.h>
#include <stack>
bool ok(char *w) {
std::stack<char> s;
char c;
for(int i = 0; isprint((c = w[i])); ++i) {
if(c == '[' || c == '(')
s.push(c);
else {
if(s.empty())
return false;
if(c == ')') {
if(s.top() != '(')
return false;
}
else {
if(s.top() != '[')
return false;
}
s.pop();
}
}
return s.empty();
}
unsigned int readUInt() {
unsigned int ret = 0;
char w[20];
std::cin.getline(w, 20);
for(int i = 0; i < 20; ++i) {
if(!(w[i] >= '0' && w[i] <= '9'))
break;
ret = ret * 10 + (w[i]-'0');
}
return ret;
}
int main() {
char w[200];
unsigned int n = readUInt();
for(unsigned int i = 0; i < n; ++i) {
std::cin.getline(w, 200);
if(ok(w))
std::cout << "Yes" << std::endl;
else
std::cout << "No" << std::endl;
}
}