Advertisement
Guest User

Untitled

a guest
Nov 28th, 2014
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.97 KB | None | 0 0
  1. #include <iostream>
  2. #include <stack>
  3. using namespace std;
  4. stack<char> s;
  5. bool check(char c1 ,char c2)
  6. {
  7. switch(c1)
  8. {
  9. case('('):
  10. if(c2 == ')')
  11. {
  12. return true;
  13. }
  14. break;
  15. case('['):
  16. if(c2 == ']')
  17. {
  18. return true;
  19. }
  20. break;
  21. case('{'):
  22. if(c2 == '}')
  23. {
  24. return true;
  25. }
  26. break;
  27. default:
  28. return false;
  29. }
  30. }
  31. int main()
  32. {
  33. string x;
  34. cin >> x;
  35. s.push(x[0]);
  36. for(int i = 1; i < x.size(); ++i)
  37. {
  38. if(!s.empty())
  39. {
  40. if(check(s.top(), x[i]))
  41. {
  42. s.pop();
  43. }
  44. else{
  45. s.push(x[i]);
  46. }
  47. }
  48. else
  49. {
  50. s.push(x[i]);
  51. }
  52. }
  53. if(s.empty())
  54. {
  55. cout << "yes";
  56. }
  57. else
  58. {
  59. cout << "no";
  60. }
  61. return 0;
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement