Advertisement
Josif_tepe

Untitled

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