关于运行时错误
  • 板块灌水区
  • 楼主wangyibo201026
  • 当前回复4
  • 已保存回复4
  • 发布时间2021/10/8 17:56
  • 上次更新2023/11/4 04:20:37
查看原帖
关于运行时错误
363006
wangyibo201026楼主2021/10/8 17:56

下面这段代码说运行时错误,有哪位大佬康康:

#include<bits/stdc++.h>

using namespace std;

string s;
stack<char> stk;
int _a, _p;

int main(){
	cin >> s;
	for(int i = 0; i < s.size(); i++){
		char x = stk.top();
		if(!stk.empty() && s[i] == 'P' && x == 'A'){
			stk.pop();
		}
		else{
			stk.push(s[i]);
		}
	}
	while(!stk.empty()){
		char x = stk.top();
		if(x == 'A'){
			_a++;
		}
		else{
			_p++;
		}
	}
	if(!_p % 2){
		cout << _a;
	}
	else{
		cout << _a + 1;
	}
	cout << _p << " " << _a;
	return 0;
}

运行时错误在第一个循环。

2021/10/8 17:56
加载中...