Advertisement
Josif_tepe

Untitled

Feb 17th, 2021
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.87 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <stack>
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8.   string o;
  9.   cin>>o;
  10.   stack<char>p;
  11.   for(int y=0; y<o.size(); y+=1){
  12.       if(o[y] == '(' or o[y] == '{' or o[y] == '[') {
  13.           p.push(o[y]);
  14.       }
  15.       else {
  16.           if(o[y] == ')' and  !p.empty() and p.top() == '(') {
  17.               p.pop();
  18.           }
  19.           else if(o[y] == '}' and !p.empty() and p.top() == '{') {
  20.               p.pop();
  21.           }
  22.           else if(o[y] == ']' and !p.empty() and p.top() == '[') {
  23.               p.pop();
  24.           }
  25.           else {
  26.               cout << "NO" << endl;
  27.               return 0;
  28.           }
  29.       }
  30.            
  31.     }
  32.  
  33.        
  34.  
  35.     if(p.empty()) {
  36.         cout << "YES" << endl;
  37.     }
  38.     else {
  39.         cout << "NO" << endl;
  40.     }
  41.    
  42.    
  43.    
  44.    
  45.     return 0;
  46. }
  47. // ]]][[[[
  48.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement