Guest User

Untitled

a guest
Jun 21st, 2018
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.28 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3. #include <stack>
  4.  
  5. int main() {
  6. //code
  7. int tc = 0;
  8. // std::stack<char> opex;
  9. cin>>tc;
  10. char c = '{';
  11. char& tmp = c;
  12. char top = '{';
  13. if (tmp == top)
  14. cout<<"same";
  15. else
  16. cout<<"not same";
  17. // std::string exp;
  18. // std::string::iterator it;
  19. while (tc > 0)
  20. {
  21. tc--;
  22. std::stack<char> opex;
  23. //cin>>tc;
  24. std::string exp;
  25. std::string::iterator it;
  26. cin>>exp;
  27. cout<<"input is "<<exp;
  28. char top,tmp;
  29. for (it = exp.begin(); it!=exp.end();it++)
  30. {
  31. if (*it == '[' || *it == '{' || *it == '(')
  32. {
  33. cout<<"pushing"<<"n";
  34. opex.push((char)*it);
  35. }
  36. else
  37. {
  38. top = opex.top();
  39. //opex.pop();
  40. tmp = *it;
  41. cout<<"top is "<<top<<" tmp is "<<tmp<<"n";
  42.  
  43. if (top == tmp)
  44. {
  45. cout<<"same"<<"n";
  46. //break;
  47. }
  48. else
  49. {
  50. cout<<"not same"<<"n";
  51. break;
  52. }
  53. opex.pop();
  54. //cout<<"looping";
  55. }
  56. }
  57. if (opex.empty())
  58. cout<<"balanced"<<"n";
  59. else
  60. {
  61. cout<<"not balanced"<<"n";
  62. while (!opex.empty())
  63. opex.pop();
  64. }
  65.  
  66. }
  67. return 0;
Add Comment
Please, Sign In to add comment