Advertisement
nicuvlad76

Untitled

Feb 18th, 2023
690
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.66 KB | None | 0 0
  1. #include <fstream>
  2. using namespace std;
  3. ///848
  4. ifstream fin("paranteze1.in");
  5. ofstream fout("paranteze1.out");
  6.  
  7. char st[300];
  8. int n;
  9. int main() {
  10.     fin>>n;
  11.     for(int k=1;k<=n;k++)
  12.     {
  13.         fin>>st;
  14.         int ok=1;///pp ca este corect parantezata
  15.         int top=0;
  16.         for(int i=0; st[i] && ok==1 ;i++)
  17.             if(st[i]=='(') top++;///push=adugare
  18.             else
  19.                 if(top>0) ///stiva vida
  20.                   top--; ///pop= stergere
  21.                 else
  22.                     ok=0; ///daca incepe cu ')'
  23.         if(top>0)ok=0;///mai sunt perente deschise nesterse
  24.  
  25.         fout<<ok<<"\n";
  26.     }
  27.  
  28.     return 0;
  29. }
  30.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement