-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path4949.cpp
More file actions
40 lines (33 loc) · 907 Bytes
/
4949.cpp
File metadata and controls
40 lines (33 loc) · 907 Bytes
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
#include<iostream>
#include<string>
#include<stack>
#define N 105
using namespace std;
int main()
{
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
string str;
int i;
getline(cin, str);
stack<char> st;
while(str.compare(".")){
bool ans = true;
while(!st.empty()) st.pop();
for(i=0; i<str.length(); i++){
if(str[i]=='(' || str[i]=='[') st.push(str[i]);
else if(str[i]==')' || str[i]==']'){
if(!st.empty() && st.top()=='(' && str[i]==')') st.pop();
else if(!st.empty() && st.top()=='[' && str[i]==']') st.pop();
else{
ans = false;
break;
}
}
}
if(ans && st.empty()) cout << "yes" << endl;
else cout << "no" << endl;
getline(cin, str);
}
return 0;
}