Advertisement
Guest User

Untitled

a guest
Oct 21st, 2019
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.67 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main(){
  5. int n; cin >> n;
  6. string z;
  7. getline(cin,z);
  8. for(int j = 0; j < n; j++){
  9. getline(cin,z);
  10. bool ok = true;
  11. deque<int> deq;
  12. for(int i = 0; i < z.size();i++){
  13.  
  14. if(z[i]=='('||z[i]=='['||z[i]=='{'){
  15. if(i!=0&&z[i-1]==':'){
  16. //cout << "lol";
  17. continue;
  18. }
  19. deq.push_back(z[i]);
  20. }
  21.  
  22. else if(z[i]==')'||z[i]==']'||z[i]=='}'){
  23. if(i!=0&&z[i-1]==':'){
  24. //cout << "lol";
  25. continue;
  26. }
  27.  
  28. if(deq.empty()){
  29. cout << 1 << "\n";
  30. ok = false;
  31. break;
  32. }
  33. else{
  34. int x = deq.back();
  35. // cout << x << " " << z[i];
  36. int cnt = 0;
  37. if(z[i]==')'){
  38. cnt = 1;
  39. }else{
  40. cnt = 2;
  41. }
  42. if(z[i]==x+cnt){
  43. deq.pop_back();
  44. continue;
  45. }else{
  46. cout << 2 <<"\n";
  47. ok = false;
  48. break;
  49. }
  50.  
  51. }
  52. }
  53. }
  54. if(ok&&!deq.empty()){
  55. cout << 3 <<"\n";
  56. }
  57. else if(ok&&deq.empty()){
  58. cout << 0 << "\n";
  59. }
  60. }
  61.  
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement