-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathteste.cpp
More file actions
41 lines (38 loc) · 957 Bytes
/
teste.cpp
File metadata and controls
41 lines (38 loc) · 957 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
41
#include <bits/stdc++.h>
using namespace std;
main(){
int n;
string e;
bool fail;
stack<char> q;
cin >> n;
cin.ignore();
for(int i=0;i<n;i++){
getline(cin,e);
fail = false;
for(int j=0;j<e.size();j++){
if(e[j]=='(' or e[j]=='{' or e[j]=='[')
q.push(e[j]);
else if(q.empty() or (e[j]==']' and q.top()!='[')){
fail = true;
break;
}
else if(q.empty() or (e[j]==')' and q.top()!='(')){
fail = true;
break;
}
else if(q.empty() or (e[j]=='}' and q.top()!='{')){
fail = true;
break;
}
else{
q.pop();
}
}
if(fail or !q.empty())
cout << "N" << endl;
else
cout << "S" << endl;
while(!q.empty()) q.pop();
}
}