求教
C题
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, k;
cin >> n >> k;
string s;
cin >> s;
for (int i = 0; i < k; i++) {
size_t p= s.find('I');
if(p==0&&s[1]!='('&&s[1]!=')'){
printf("I");
return 0;
}
string operation;
cin >> operation;
if (operation == "backspace") {
if(s[p-1]=='('&&s[p+1]==')'){
s.erase(p-1,1);
s.erase(p,1);
}
else if(s[p-1]==')'&&s[p-2]=='('){
s.erase(p-1,1);
}
}
else if (operation == "delete") {
if(s[p-1]=='('&&s[p+1]==')'){
s.erase(p+1,1);
}
else if(s[p+1]=='('&&s[p+2]==')'){
s.erase(p+1,1);
}
}
}
cout << s << endl;
return 0;
}
各位佬求教,这个为啥答案错误啊


查看11道真题和解析