• codevs 3333 高级打字机


    3333 高级打字机

     
    题目描述 Description

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

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

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

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

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

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

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

    输入描述 Input Description

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

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

    输出描述 Output Description

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

    样例输入 Sample Input

    7

    T a

    T b

    T c

    Q 2

    U 2

    T c

    Q 2

    样例输出 Sample Output

    b

    c

    数据范围及提示 Data Size & Hint

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

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

    <高级挑战>

    对于100%的数据 n<=100000;Undo操作可以撤销Undo操作。

    栈模拟得50分,不知道为什么输入两个字符串对不了

    #include<iostream>
    #include<cstdio>
    using namespace std;
    #define maxn 100010
    int top,n;
    char a[maxn],op[4],is[4];
    int main(){
        scanf("%d",&n);
        for(int i=1;i<=n;i++){
            scanf("%s%s",op,is);
            if(op[0]=='T')a[++top]=is[0];
            if(op[0]=='U')top-=is[0]-'0';
            if(op[0]=='Q')cout<<a[is[0]-'0']<<endl;
        }
        return 0;
    }
    0分
    #include<iostream>
    #include<cstdio>
    using namespace std;
    #define maxn 100010
    int top,n;
    char a[maxn],op[4],is[4];
    int main(){
        scanf("%d",&n);
        for(int i=1, x;i<=n;i++){
            scanf ("%s", op);
            if(op[0]=='T'){
                scanf ("%s",is);
                a[++top]=is[0];
            }
            if(op[0]=='U'){
                scanf ("%d",&x);
                top-=x;
            }
            if(op[0]=='Q'){
                scanf ("%d",&x);
                cout<<a[x]<<endl;
            }
        }
        return 0;
    }
    50分
  • 相关阅读:
    ALV_TREE(二:cl_gui_simple_tree…
    ALV_TREE(一:cl_gui_alv_tree_si…
    SQLPlus命令详细说明
    PL/SQL中,declare定义变量和variable定义变量的区别?
    Oracle 多表视图更新(待看完触发器后再来看)
    Oracle 函数 Translate 的用法
    Merge into
    savepoint(回退点)
    Oracle之分页查询
    对于package中全局变量的一点点初级理解
  • 原文地址:https://www.cnblogs.com/thmyl/p/6958244.html
Copyright © 2020-2023  润新知