Code
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6+10;
string stk[N];
int hh;
int main(){
int q;
while(cin>>q){
hh=0;
for(int i=1;i<=q;i++){
int op;
cin>>op;
if(op==1){
string s;
cin>>s;
stk[hh+1]=stk[hh]+s;
hh++;
}
else if(op==2){
int k; cin>>k;
string s=stk[hh];
reverse(s.begin(),s.end());
s.erase(s.begin(),s.begin()+k);
reverse(s.begin(),s.end());
stk[++hh]=s;
}
else if(op==3){
int k; cin>>k;
cout<<stk[hh][k-1]<<endl;
}
else hh--;
}
}
return 0;
}
京公网安备 11010502036488号