Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- main()
- {
- string s;
- int a=0, b=0, c=0, d=0;
- bool p = true;
- cin >> s;
- for (int i=0; i<s.length(); i++)
- if (s[i]=='{')
- {
- int j=i;
- while (j<s.length() && s[j]!='}')
- {
- if(s[j]=='(')
- a++;
- if(s[j]==')')
- b++;
- if(s[j]=='[')
- c++;
- if(s[j]==']')
- d++;
- if (s[j]=='}')
- i=j;
- j++;
- }
- }
- if (a!=b || c!=d)
- p = false;
- if (p==true)
- {
- a = 0; b = 0; c = 0; d = 0;
- for (int i=0; i<s.length(); i++)
- if (s[i]=='[')
- {
- int j=i;
- while (j<s.length() && s[j]!=']')
- {
- if(s[j]=='(')
- a++;
- if(s[j]==')')
- b++;
- if (s[j]==']')
- i=j;
- j++;
- }
- }
- if (a!=b)
- p = false;
- if (p==true)
- {
- for (int i=0; i<s.length(); i++)
- if (s[i]=='(')
- c++;
- else if (s[i]==')')
- d++;
- if (c!=d)
- cout << "0" << endl;
- else cout << "1" << endl;
- }
- else cout << "0" << endl;
- }
- else cout << "0" << endl;
- system ("PAUSE");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement