Advertisement
Guest User

Untitled

a guest
Feb 20th, 2019
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.18 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <cstring>
  4. using namespace std;
  5.  
  6. ifstream fin("paranteze3.in");
  7. ofstream fout("paranteze3.out");
  8.  
  9. int n;
  10. char s[256];
  11. char stiva[256];
  12.  
  13. int main()
  14. {
  15. fin >> n;
  16. for(int k = 1 ; k <= n ; k ++)
  17. {
  18. fin >> s;
  19. int ok = 1;
  20. int nivel = 0;
  21. for(int i = 0 ; s[i] && ok ; i ++)
  22. if(s[i] == '(')
  23. stiva[++nivel]='(';
  24. else
  25. if(s[i] == '[')
  26. stiva[++nivel]='[';
  27. else
  28. if(nivel > 0)
  29. {
  30. if(s[i] == ')')
  31. if(stiva[nivel] == '(')
  32. nivel --;
  33. else
  34. ok = 0;
  35. else
  36. if(stiva[nivel] == '[')
  37. nivel --;
  38. else
  39. ok = 0;
  40. }
  41. else
  42. ok = 0;
  43. if(nivel > 0)
  44. ok = 0;
  45. fout << ok << "\n";
  46. }
  47. return 0;
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement