#include <iostream>
#include <stack> // stack
#include <cstdlib>
#include <string.h> //strlen
using namespace std;
bool isRes(char * str){
stack<char> str_s;
int str_len = strlen(str);
for (int y=0;y<str_len;y++){
char x = str[y];
if (x!=']' && x!='[' && x!='(' && x!=')' )
continue;
if (x=='[' || x=='('){
str_s.push(x);
}else{
if(str_s.empty()){
cout <<"右右右多duo"<<endl;
return false;
}
char z = str_s.top();
if ((z=='[' && x==']') || (z=='(' && x==')'))
str_s.pop();
else
return false;
}
}
if (!str_s.empty()){
cout<<"zuo左左duo"<<endl;
return false;
}else{
return true;
}
}
int main() {
char r[10];
cin>> r;
if (isRes(r)){
cout<<"yes"<<endl;
}else
{
cout<<"no"<<endl;
}
return 0;
}
C++ 栈stack之括号匹配
最新推荐文章于 2024-04-22 14:13:05 发布