DarkArtheme

H1

Feb 12th, 2021
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.69 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main() {
  5.     string s;
  6.     cin >> s;
  7.     bool flag = true;
  8.     string s1;
  9.     for(const auto& x : s){
  10.         if(x == '(' || x == '[' || x == '{'){
  11.             s1.push_back(x);
  12.         } else{
  13.             if(s1.empty()){
  14.                 flag = false;
  15.                 break;
  16.             }
  17.             if(x - s1.back() == 1 || x - s1.back() == 2){
  18.                 s1.pop_back();
  19.             } else{
  20.                 flag = false;
  21.                 break;
  22.             }
  23.         }
  24.     }
  25.     if(!s1.empty()){
  26.         flag = false;
  27.     }
  28.     if(flag){
  29.         cout << "yes\n";
  30.     } else{
  31.         cout << "no\n";
  32.     }
  33.     return 0;
  34. }
  35.  
Advertisement
Add Comment
Please, Sign In to add comment