Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <stack>
- using namespace std;
- int main(){
- int T;
- bool ok=true;
- stack<char>parenteses;
- stack<char>colchetes;
- stack<char>chaves;
- cin>>T;
- string expre[T];
- for(int i=0;i<T;i++)
- cin>>expre[i];
- for(int i=0;i<T;i++){
- for(int j=0;j<(int)expre[i].size();j++){
- if(expre[i][j]=='('){
- parenteses.push('(');
- }
- else if(expre[i][j]=='['){
- colchetes.push('[');
- }
- else if(expre[i][j]=='{'){
- chaves.push('{');
- }
- else if(expre[i][j]==')'){
- if(parenteses.empty()){
- ok=false;
- break;
- }
- else
- parenteses.pop();
- }
- else if(expre[i][j]==']'){
- if(colchetes.empty()){
- ok=false;
- break;
- }
- else
- colchetes.pop();
- }
- else if(expre[i][j]=='}'){
- if(chaves.empty()){
- ok=false;
- break;
- }
- else
- chaves.pop();
- }
- }
- if(!chaves.empty()){
- ok=false;
- }
- if(!colchetes.empty()){
- ok=false;
- }
- if(!parenteses.empty()){
- ok=false;
- }
- if(ok)
- cout<<"S"<<"\n";
- else
- cout<<"N"<<"\n";
- ok=true;
- while(!chaves.empty())
- chaves.pop();
- while(!colchetes.empty())
- colchetes.pop();
- while(!parenteses.empty())
- parenteses.pop();
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement