- #include<bits/stdc++.h>
- using namespace std;
- int main()
- {
- string str;
- while(cin>>str)
- {
- stack<char> sp;
- bool match=true;
- for(int i=0;i<str.length();i++)
- {
- if(str[i]=='(' || str[i]=='[' ||str[i]=='{')
- sp.push(str[i]);
- if(str[i]==')' || str[i]==']' ||str[i]=='}')
- {
- if(str.length()%2==1)
- {
- match=false;
- break;
- }
- if(sp.empty())
- {
- match=false;
- break;
- }
- if(str[i]-sp.top()==1 || str[i]-sp.top()==2)
- {
- sp.pop();
- }
- else
- {
- match=false;
- break;
- }
- }
- }
- if(match and sp.empty())
- cout<<"yes"<<endl;
- else
- cout<<"no"<<endl;
- }
- return 0;
- }
複製代碼 |