- #include<bits/stdc++.h>
- using namespace std;
- int main()
- {
- string x;
- while(cin>>x){
- int c=0;
- stack<char> n;
- if(x.length()%2){
- cout<<"no\n";
- continue;
- }
- for(int i=0;i<x.length();i++){
- if(x[i]=='(' || x[i]=='[' || x[i]=='{'){
- n.push(x[i]);
- }else if(x[i]==')' || x[i]==']' || x[i]=='}'){
- if(n.empty()){
- c++;
- break;
- }else if((x[i]-n.top())>2){
- c++;
- break;
- }else{
- n.pop();
- }
- }
- }
-
- if(n.empty() && c==0){
- cout<<"yes\n";
- }else{
- cout<<"no\n";
- }
- }
- return 0;
- }
複製代碼 |