#include<iostream>
#include<stack>
using namespace std;
void main(){
int i,invalid = 0;
char a[50];
char *s=a;
stack<char> st;
st.empty();
cin >> a;
while(*s!='\0') {
if(*s == '['|| *s == '(')
st.push(*s);
else {
if(*s == ']') {
if(st.top() != '[')
{
invalid = 1;
break;
}
else
st.pop();
}
if(*s == ')')
{
if(st.top()!='(')
{
invalid = 1;
break;
}
else
st.pop();
}
}
s++;
}
if(!st.empty())
invalid = 1;
if(invalid)
cout<<"invalid!"<<endl;
else
cout<<"ok!"<<endl; cin>>i;
}
括号匹配检验 c++
最新推荐文章于 2024-07-19 16:13:00 发布