-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaoj1173.cpp
More file actions
89 lines (85 loc) · 1.51 KB
/
aoj1173.cpp
File metadata and controls
89 lines (85 loc) · 1.51 KB
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <cstring>
#include <cctype>
#include <sstream>
#include <set>
#include <map>
#include <queue>
#include <complex>
using namespace std;
#define REP(i,n) for(int i = 0; i < (int)n; i++)
#define FOR(i,a,b) for(int i = a; i < (int)b; i++)
const int INF = 1<<28;
string input;
int find(int a, int p) {
int btn[2] = {};
FOR(i, p, input.size()) {
if(a) {
if(input[i] == '[')
btn[0]++;
if(input[i] == ']')
btn[0]--;
if(btn[0] < 0) return 1;
if(input[i] == '(')
btn[1]++;
if(input[i] == ')') {
btn[1]--;
if(!btn[0] && !btn[1])
return 0;
}
}
else {
if(input[i] == '(')
btn[0]++;
if(input[i] == ')')
btn[0]--;
if(btn[0] < 0) return 1;
if(input[i] == '[')
btn[1]++;
if(input[i] == ']') {
btn[1]--;
if(!btn[0] && !btn[1])
return 0;
}
}
}
return 1;
}
int main() {
while(getline(cin, input)) {
if(input == ".") break;
int cnt = 0;
int chk[2] = {};
REP(i, input.size()) {
if(input[i] == '(') {
cnt += find(1, i);
chk[1]++;
}
if(input[i] == '[') {
cnt += find(0, i);
chk[0]++;
}
if(input[i] == ')') {
chk[1]--;
if(chk[1] < 0) cnt++;
}
if(input[i] == ']') {
chk[0]--;
if(chk[0] < 0) cnt++;
}
}
if(chk[0] || chk[1]) cnt++;
cout << (cnt ? "no" : "yes") << endl;
}
return 0;
}