-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path4949.cpp
More file actions
49 lines (46 loc) · 1.18 KB
/
4949.cpp
File metadata and controls
49 lines (46 loc) · 1.18 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
#include <iostream>
#include <stack>
#include <string>
using namespace std;
int main() {
stack<char> stack;
string par;
int flag;
while (1) {
flag = 0;
getline(cin, par);
if (par == ".") break;
if (par.at(par.size() - 1) != '.') {
cout << "no" << endl;
continue ;
}
for (int j = 0; j < par.size(); j++) {
if (par.at(j) == '(')
stack.push('(');
else if (par.at(j) == ')') {
if (stack.empty() || stack.top() != '(') {
flag = 1;
break ;
}
stack.pop();
}
else if (par.at(j) == '[')
stack.push('[');
else if (par.at(j) == ']') {
if (stack.empty() || stack.top() != '[') {
flag = 1;
break ;
}
stack.pop();
}
}
if (stack.empty() && flag != 1)
cout << "yes" << endl;
else {
cout << "no" << endl;
while (!stack.empty())
stack.pop();
}
}
return (0);
}