Advertisement
Guest User

Untitled

a guest
May 19th, 2019
96
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. #include <string>
  3. #include <vector>
  4.  
  5. using namespace std;
  6. int main()
  7. {
  8. string st = "({[]})";
  9. vector<char> a;
  10. int p = st.size() - 1;
  11. for (int i = 0; i < p; i++)
  12. {
  13. a.push_back(st[i]);
  14. }
  15. vector<char> b;
  16. bool r = true;
  17. int i = 0;
  18. if ((a[i] == ')') || (a[i] == '}') || (a[i] == ']'))
  19. {
  20. r = false;
  21. }
  22. for (i = 1; i < a.size(); i++)
  23. {
  24. if ((a[i] == '(') || (a[i] == '{') || (a[i] == '['))
  25. {
  26. b.push_back(a[i]);
  27. }
  28. if (a[i] == ')')
  29. {
  30. if (a[i - 1] == '(')
  31. {
  32. b.erase(b.end()-1);
  33. }
  34. else
  35. {
  36. r = false;
  37. }
  38. }
  39. if (a[i] == '}')
  40. {
  41. if (a[i - 1] == '{')
  42. {
  43. b.erase(b.end()-1);
  44. }
  45. else
  46. {
  47. r = false;
  48. }
  49. }
  50. if (a[i] == ']')
  51. {
  52. if (a[i - 1] == '[')
  53. {
  54. b.erase(b.end()-1);
  55. }
  56. else
  57. {
  58. r = false;
  59. }
  60. }
  61. cout << r << endl;
  62. system("pause");
  63. return 0;
  64. }
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement