zhan
2023-10-22 09:48:52
发布于:北京
#include<bits/stdc++.h>
using namespace std;
char st[100],TOP=0;
//入栈
void push(char x){
TOP++;
st[TOP]=x;
}
//出栈
void pop(){
TOP--;
}
//取栈顶元素
int top(){
return st[TOP];
}
//判断栈是否为空
bool empty(){
return TOP0;
//if(TOP0) return true;
//else return false;
}
//清空栈
void clear(){
TOP=0;
}
//栈的大小
int size(){
return TOP;
}
int main(){
string a;
cin>>a;
for(int i=0;i<a.size();i++){
if(a[i]'(' || a[i]'['){
push(a[i]);
}
if(a[i]')'){
if(top()'(') pop();
else{
cout<<"Wrong";
return 0;
}
}
if(a[i]']'){
if(top()'[') pop();
else{
cout<<"Wrong";
return 0;
}
}
}
if(empty()) cout<<"OK";
else cout<<"Wrong";
return 0;
}
全部评论 1
#include<bits/stdc++.h>
using namespace std;
char st[100],TOP=0;
//入栈
void push(char x){
TOP++;
st[TOP]=x;
}
//出栈
void pop(){
TOP--;
}
//取栈顶元素
int top(){
return st[TOP];
}
//判断栈是否为空
bool empt2023-10-22 来自 北京
0
有帮助,赞一个