[模拟赛] T1 高级打字机

时间:2022-01-27 20:32:02

Description

早苗入手了最新的高级打字机。最新款自然有着与以往不同的功能,那就是它具备撤销功能,厉害吧。

请为这种高级打字机设计一个程序,支持如下3种操作:

1.T x:在文章末尾打下一个小写字母x。(type操作)

2.U x:撤销最后的x次修改操作。(Undo操作)

(注意Query操作并不算修改操作)

3.Q x:询问当前文章中第x个字母并输出。(Query操作)

文章一开始可以视为空串。

Input

第1行:一个整数n,表示操作数量。

以下n行,每行一个命令。保证输入的命令合法。

Output

每行输出一个字母,表示Query操作的答案。

Range

对于40%的数据 n<=200;

对于100%的数据 n<=100000;保证Undo操作不会撤销Undo操作。

Solution

太水...直接数组模拟栈即可..

#include<cstdio>
#include<cstring>
#include<iostream>
using namespace std;

int n,top;
];

signed main(){
/*    freopen("type.in","r",stdin);
    freopen("type.out","w",stdout);*/
    scanf("%d",&n);
    ;i<=n;i++){
        char ch;cin>>ch;
        if(ch=='T'){
            char ch1;cin>>ch1;
            a[++top]=ch1;
        }
        else if(ch=='Q'){
            int x;cin>>x;
            printf("%c\n",a[x]);
        }
        else{
            int x;cin>>x;
            top-=x;
        }
    }
    /*fclose(stdin);
    fclose(stdout);*/
    ;
}