Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <stack>
- using namespace std;
- stack<char> s;
- bool check(char c1 ,char c2)
- {
- switch(c1)
- {
- case('('):
- if(c2 == ')')
- {
- return true;
- }
- break;
- case('['):
- if(c2 == ']')
- {
- return true;
- }
- break;
- case('{'):
- if(c2 == '}')
- {
- return true;
- }
- break;
- default:
- return false;
- }
- }
- int main()
- {
- string x;
- cin >> x;
- s.push(x[0]);
- for(int i = 1; i < x.size(); ++i)
- {
- if(!s.empty())
- {
- if(check(s.top(), x[i]))
- {
- s.pop();
- }
- else{
- s.push(x[i]);
- }
- }
- else
- {
- s.push(x[i]);
- }
- }
- if(s.empty())
- {
- cout << "yes";
- }
- else
- {
- cout << "no";
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement