- #include <bits/stdc++.h>
- using namespace std;
- string str;
- int main()
- {
- 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.empty())
- {
- match=false;
- break;
- }
- if(str[i]-sp.top()==1 || str[i]-sp.top()==2)
- {
- sp.pop();
- }
- else
- {
- match=false;
- break;
- }
- }
- }
- if(sp.empty() && match==true)
- cout<<"yes\n";
- else
- cout<<"no\n";
- }
- return 0;
- }
複製代碼 |