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

  3. int main()
  4. {
  5.     string s;
  6.     while(cin>>s){
  7.         bool m=true;
  8.         stack <char> sp;
  9.         for(int i=0;i<s.length();i++){
  10.             if(s[i]=='('||s[i]=='['||s[i]=='{'){
  11.                 sp.push(s[i]);
  12.             }
  13.             if(s[i]==')'||s[i]==']'||s[i]=='}'){
  14.                 if(sp.empty()){
  15.                     m=false;
  16.                     break;
  17.                 }
  18.                 else if(s[i]-sp.top()==2||s[i]-sp.top()==1){
  19.                     sp.pop();
  20.                 }
  21.             }
  22.         }
  23.         if(sp.empty()&&m){
  24.             cout<<"yes"<<endl;
  25.         }else{
  26.             cout<<"no"<<endl;
  27.         }
  28.     }
  29.     return 0;
  30. }
複製代碼

TOP

返回列表