Manunich

Untitled

Aug 5th, 2013
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. using namespace std;
  3. const int MAX=255;
  4. char a[MAX], s[MAX];
  5. int k=0;
  6. int main() {
  7.     cin>>s;
  8.     for(int i = 0; i <strlen(s); i++) {
  9.         if (s[i]=='(' || s[i]=='[' || s[i]=='{') a[k++]=s[i];
  10.         if ((s[i]==')' && a[k-1]=='(' || s[i]==']' && a[k-1]=='[' || s[i]=='}' && a[k-1]=='{') && k>0)k--;
  11.     }
  12.     if (k==0) cout<<"yes"; else cout<<"no";
  13.     return 0;
  14. }
Advertisement
Add Comment
Please, Sign In to add comment