题目链接
题意
1、append(str),向记事本插入字符串 str(英文字符)
2、delete(k),删除记事本最后k个字符(保证不为空串)
3、print(k),输出记事本第k个字符(保证不为空串)
4、undo(),撤销最近的1(或者)操作,使记事本回到1(或者2)操作之前的状态
思路
- 根据题意模拟即可,注意多组输入
参考代码
#include<bits/stdc++.h>
using namespace std;
string record[1000010];
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int q;
while(cin>>q)
{
record[0]="";
int pos=1,pre=0;
string notepad="";
int tmp;
for(int i=0; i<q; i++)
{
cin>>tmp;
if(tmp==1)
{
string tmp2;
cin>>tmp2;
notepad.append(tmp2);
record[pos]=notepad;
pos++;
}
else if(tmp==2)
{
int k;
cin>>k;
notepad.erase(notepad.size()-k,k);
record[pos]=notepad;
pos++;
}
else if(tmp==3)
{
int k;
cin>>k;
cout<<notepad[k-1]<<endl;
}
else if(tmp==4)
{
pos-=1;
notepad=record[pos-1];
}
}
}
}