Advertisement
Josif_tepe

Untitled

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