【求助】运行错误!
  • 板块灌水区
  • 楼主CuSO4_and_5H2O
  • 当前回复10
  • 已保存回复10
  • 发布时间2022/4/20 17:11
  • 上次更新2023/10/28 03:15:11
查看原帖
【求助】运行错误!
231946
CuSO4_and_5H2O楼主2022/4/20 17:11

五个答案证券,一个运行错误,而且这个题没数组啊

题目

运行结果

#include<bits/stdc++.h>
using namespace std;
string a;
stack<char> x;

signed main() {
     getline(cin, a);
     for(int i=0;i<a.size();i++){
     	if(a[i]=='[' || a[i]=='(') x.push(a[i]);
     	else{
     		if(a[i]==']'){
     			if(x.top()=='[' && !x.empty()) x.pop();
     			else{
     				cout<<"Wrong";
     				return 0;
				 }
			 }
			 if(a[i]==')'){
     			if(x.top()=='(' && !x.empty()) x.pop();
     			else{
     				cout<<"Wrong";
     				return 0;
				 }
			 }
		 }
	 } 
	if(!x.empty()) cout<<"Wrong";
	else cout<<"OK";
	return 0;
}

2022/4/20 17:11
加载中...