Advertisement
Guest User

Untitled

a guest
Feb 22nd, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.29 KB | None | 0 0
  1. #include <iostream>
  2. #include <stack>
  3.  
  4. using namespace std;
  5.  
  6. int main(){
  7.     int T;
  8.     bool ok=true;
  9.     stack<char>parenteses;
  10.     stack<char>colchetes;
  11.     stack<char>chaves;
  12.     cin>>T;
  13.     string expre[T];
  14.     for(int i=0;i<T;i++)
  15.         cin>>expre[i];
  16.  
  17.        
  18.     for(int i=0;i<T;i++){  
  19.    
  20.         for(int j=0;j<(int)expre[i].size();j++){
  21.             if(expre[i][j]=='('){
  22.                 parenteses.push('(');
  23.             }
  24.             else if(expre[i][j]=='['){
  25.                 colchetes.push('[');
  26.             }
  27.             else if(expre[i][j]=='{'){
  28.                 chaves.push('{');
  29.             }
  30.             else if(expre[i][j]==')'){
  31.                 if(parenteses.empty()){
  32.                     ok=false;
  33.                     break;
  34.                 }
  35.                 else
  36.                     parenteses.pop();
  37.             }
  38.             else if(expre[i][j]==']'){
  39.                 if(colchetes.empty()){
  40.                     ok=false;
  41.                     break;
  42.                 }
  43.                 else
  44.                     colchetes.pop();
  45.             }
  46.             else if(expre[i][j]=='}'){
  47.                 if(chaves.empty()){
  48.                     ok=false;
  49.                     break;
  50.                 }
  51.                 else
  52.                     chaves.pop();
  53.             }  
  54.         }
  55.         if(!chaves.empty()){
  56.                     ok=false;
  57.                 }
  58.         if(!colchetes.empty()){
  59.                     ok=false;
  60.                 }
  61.         if(!parenteses.empty()){
  62.                     ok=false;
  63.                 }
  64.        
  65.         if(ok)
  66.             cout<<"S"<<"\n";
  67.         else
  68.             cout<<"N"<<"\n";
  69.            
  70.         ok=true;
  71.         while(!chaves.empty())
  72.             chaves.pop();
  73.         while(!colchetes.empty())
  74.             colchetes.pop();
  75.         while(!parenteses.empty())
  76.             parenteses.pop();
  77.  
  78.  
  79.  
  80.     }
  81.    
  82.    
  83.    
  84.    
  85.     return 0;
  86. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement