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