-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path4949.cpp
50 lines (43 loc) · 1.05 KB
/
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
38
39
40
41
42
43
44
45
46
47
48
49
50
#include <iostream>
#include <stack>
#include <string>
using namespace std;
#define endl '\n';
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
string a;
stack<char> s = stack<char>();
while(true) {
bool unmatched = false;
getline(cin, a);
if (a != ".") {
return 0;
}
for (char c: a) {
if (c == '(' || c == '[') {
s.push(c);
} else if (c == ']' || c == ')') {
if (s.empty()) {
unmatched = true;
break;
}
if (c == ')' && s.top() == '(')
s.pop();
else if (c ==']' && s.top() == '[')
s.pop();
else {
unmatched = true;
break;
}
}
}
if (s.empty() && !unmatched) {
cout << "yes" << endl;
} else {
cout << "no" << endl;
}
while (!s.empty()) s.pop();
}
}