Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include<stack>
- using namespace std;
- int main()
- {
- string n;
- cin>>n;
- stack<char>s;
- for(int i=0;i<n.size();i++)
- {
- if(n[i]=='(' || n[i]=='{' || n[i]=='[')
- {
- s.push(n[i]);
- }
- if(n[i]==')')
- {
- if(!s.empty() && s.top()=='(')
- {
- s.pop();
- }else
- {
- cout<<" ne e tocno"<<endl;
- return 0;
- }
- }
- if(n[i]==']')
- {
- if(!s.empty() && s.top()=='[')
- {
- s.pop();
- }else
- {
- cout<<" ne e tocno"<<endl;
- return 0;
- }
- }
- if(n[i]=='}')
- {
- if(!s.empty() && s.top()=='{')
- {
- s.pop();
- }else
- {
- cout<<" ne e tocno"<<endl;
- return 0;
- }
- }
- }
- cout<<"tocno"<<endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement