思路:很好的一题字符串模拟题
收获:对string方法的调用更加熟悉灵活(具体可以看下方Accode,很通俗易懂滴!)
ACcode:
#include <bits/stdc++.h>
using namespace std;
#define int long long
string s,ss;
int n,k;
void solve() {
cin>>n>>k>>s;
while(k--) {
cin>>ss;
int j=s.find('I');
if(ss=="backspace") {
if(s[j-1]=='('&&s[j+1]==')') {
s.erase(j-1,1);
s.erase(j,1);
} else {
if(j>=1)s.erase(j-1,1);
}
} else if(ss=="delete") {
s.erase(j+1,1);
} else if(ss=="<-") {
if(j>0) {
s[j]=s[j-1];
s[j-1]='I';
}
} else {
if(j<s.size()-1) {
s[j]=s[j+1];
s[j+1]='I';
}
}
}
cout<<s<<"\n";
}
signed main() {
ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
int tt=1;
//cin>>tt;
while(tt--) {
solve();
}
return 0;
}
over~