- #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(sp.size()==0)
- {
- match=false;
- break;
- }
- if(str[i]-sp.top()==2 || str[i]-sp.top()==1)
- {
- sp.pop();
- }
- }
- }
- if(match==true && sp.size()==0)
- {
- cout<<"yes\n";
- }
- else
- {
- cout<<"no\n";
- }
- }
- }
複製代碼 |