forked from encrypted-def/basic-algo-lecture
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path4949.cpp
37 lines (36 loc) · 825 Bytes
/
4949.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
// Authored by : BaaaaaaaaaaarkingDog
// Co-authored by : -
// http://boj.kr/9dd230a7a6cf4fdaa3f2abde6c96c59c
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
while(true){
string a;
getline(cin, a);
if(a == ".") break;
stack<char> s;
bool isValid = true;
for(auto c : a){
if(c == '(' || c == '[') s.push(c);
else if(c == ')'){
if(s.empty() || s.top() != '('){
isValid = false;
break;
}
s.pop();
}
else if(c == ']'){
if(s.empty() || s.top() != '['){
isValid = false;
break;
}
s.pop();
}
}
if(!s.empty()) isValid = false;
if(isValid) cout << "yes\n";
else cout << "no\n";
}
}