ANS 标准STACK代码

jinpeiyu 2023-12-09 15:08:24 2023-12-09 15:08:45 10 返回题目

#include <bits/stdc++.h>
using namespace std;
stack<char> c;
int main(){
	string l;
	cin>>l;
	int n=l.size();
	c.push('!');
	for(int i=0;i<n;i++){
		if(l[i]==')'){if( c.top()=='(')c.pop();else {cout<<"Wrong";return 0;}}
		else if(l[i]==']'){if( c.top()=='[')c.pop();else {cout<<"Wrong";return 0;}}
		else c.push(l[i]);
	}
	if(c.size()==1)cout<<"OK"<<endl;
	else cout<<"Wrong"<<endl;
	return 0;
}
{{ vote && vote.total.up }}