Advertisement
Guest User

Untitled

a guest
Jul 20th, 2019
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.44 KB | None | 0 0
  1. #include <iostream>
  2. #define maxn 1000000
  3. #include <string>
  4.  
  5. using namespace std;
  6.  
  7. char a[maxn+10];
  8. int length;
  9. int head;
  10.  
  11. int stack_init() {
  12. length = 0;
  13. }
  14.  
  15. bool stack_is_empty() {
  16. if (length == 0)
  17. return true;
  18. else return false;
  19. }
  20.  
  21. bool add_element (char c) {
  22. if (head == maxn)
  23. return false;
  24. a[head] = c;
  25. head++;
  26. length++;
  27. return true;
  28. }
  29.  
  30. bool take_element (char c) {
  31. if (stack_is_empty())
  32. return false;
  33. c = a[--head];
  34. length--;
  35. return true;
  36. }
  37.  
  38. char top_element() {
  39. if (!stack_is_empty())
  40. return a[length - 1];
  41. }
  42.  
  43. int main() {
  44. bool answer = true;
  45. char s[256];
  46. cin>>s;
  47. for (int i = 0; i< sizeof(s); i++) {
  48. if ((int)(s[i]) == 40 || (int)(s[i]) == 91 || (int)(s[i]) == 123) {
  49. add_element(s[i]);
  50. }
  51. else {
  52. if (stack_is_empty()) {
  53. answer = false;
  54. break;
  55. }
  56. else {
  57. char last = top_element();
  58. if (((int)(s[i]) == 91 && (int)(last) == 93)||((int)(s[i]) == 40 && (int)(last) == 41)||((int)(s[i]) == 123 && (int)(last) == 125))
  59. take_element(s[i]);
  60. else {
  61. answer = false;
  62. break;
  63. }
  64. }
  65. }
  66. }
  67. if (answer)
  68. cout<<"YES";
  69. else cout<<"NO";
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement