drof13

Untitled

Dec 5th, 2021
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.85 KB | None | 0 0
  1. #include<iostream>
  2. #include <cmath>
  3. #include <iostream>
  4. #include <iterator>
  5. #include <map>
  6. #include <set>
  7. #include <string>
  8. #include <vector>
  9. #include <algorithm>
  10. #include <stack>
  11.  
  12. #define int long long
  13. #define pb push_back
  14.  
  15. using namespace std;
  16.  
  17. signed main() {
  18.     ios_base::sync_with_stdio(0);
  19.     cin.tie(0);
  20.     cout.tie(0);
  21.     string s;
  22.     cin >> s;
  23.     stack<int> st;
  24.     for (int i = 0; i < s.size(); i++) {
  25.         if (s[i] == '(' || s[i] == '[' || s[i] == '{') {
  26.             st.push(s[i]);
  27.         }
  28.         if (s[i] == ')' || s[i] == ']' || s[i] == '}') {
  29.             if (st.top() == s[i]) {
  30.                 st.pop();
  31.             } else {
  32.                 cout << "no";
  33.                 return 0;
  34.             }
  35.         }
  36.     }
  37.     if (st.size() == 0) {
  38.         cout << "yes";
  39.     } else {
  40.         cout << "no";
  41.     }
  42. }
  43.  
Advertisement
Add Comment
Please, Sign In to add comment