下面这段代码说运行时错误,有哪位大佬康康:
#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;
}
运行时错误在第一个循环。