#include<iostream> #include<stack> #include<cstring> using namespace std; char str[1000005]; int main() { stack<char>s; int i,l,flag,ans; while(cin>>str) { l=strlen(str); flag=1;ans=0; for(i=0;i<l;i++) { if(str[i]=='{'||str[i]=='<'||str[i]=='('||str[i]=='[') s.push(str[i]); else { if(s.empty()) { flag=0; break; } else { if(str[i]=='>') { if(s.top()!='<') ans++; } else if(str[i]=='}') { if(s.top()!='{') ans++; } else if(str[i]==')') { if(s.top()!='(') ans++; } else if(str[i]==']') { if(s.top()!='[') ans++; } s.pop(); } } } if(!s.empty()||flag==0) cout<<"Impossible"<<endl; else cout<<ans<<endl; } return 0; }
stack <stack> (parentheses match)
Guess you like
Origin http://43.154.161.224:23101/article/api/json?id=325942618&siteId=291194637
Recommended
Ranking