返回列表 發帖
  1. #include<bits/stdc++.h>
  2. using namespace std;

  3. int main()
  4. {
  5.     string x;
  6.     while(cin>>x){
  7.         int c=0;
  8.         stack<char> n;
  9.         if(x.length()%2){
  10.             cout<<"no\n";
  11.             continue;
  12.         }
  13.         for(int i=0;i<x.length();i++){
  14.             if(x[i]=='(' || x[i]=='[' || x[i]=='{'){
  15.                 n.push(x[i]);
  16.             }else if(x[i]==')' || x[i]==']' || x[i]=='}'){
  17.                 if(n.empty()){
  18.                     c++;
  19.                     break;
  20.                 }else if((x[i]-n.top())>2){
  21.                     c++;
  22.                     break;                    
  23.                 }else{
  24.                     n.pop();
  25.                 }
  26.             }
  27.         }
  28.    
  29.         if(n.empty() && c==0){
  30.             cout<<"yes\n";
  31.         }else{
  32.             cout<<"no\n";
  33.         }
  34.     }

  35.     return 0;
  36. }
複製代碼

TOP

返回列表