#include <iostream>
#include <cstdio>
#include <vector>
#include <cstring>
#include <queue>
#include<stack>
using namespace std;
bool check(string s){
stack<char> mys;
for(int i=0;i<s.length();i++){
if(s[i]=='(' || s[i]=='[' || s[i]=='{')
mys.push(s[i]);
else if(s[i]==')'){
if(mys.empty())
return false;
char c=mys.top();
mys.pop();
if(c=='(')
continue;
else
return false;
}
else if(s[i]==']'){
if(mys.empty())
return false;
char c=mys.top();
mys.pop();
if(c=='[')
continue;
else
return false;
}
else if(s[i]=='}'){
if(mys.empty())
return false;
char c=mys.top();
mys.pop();
if(c=='{')
continue;
else
return false;
}
}
if(mys.empty())
return true;
else
return false;
}
int main(){
string s;
while(1){
getline(cin,s);
if(check(s))
cout << "yes\n";
else
cout << "no\n";
}
return 0;
}
栈匹配括号(STL实现)
最新推荐文章于 2023-04-24 13:07:53 发布