BZOJ 1507 Editor


<ext/rope>真是一个牛b的头文件......

Time Limit: 5000MS Memory Limit: 165888KB 64bit IO Format: %lld & %llu

Description

Input

输入文件editor.in的第一行是指令条数t,以下是需要执行的t个操作。其中: 为了使输入文件便于阅读,Insert操作的字符串中可能会插入一些回车符,请忽略掉它们(如果难以理解这句话,可以参考样例)。 除了回车符之外,输入文件的所有字符的ASCII码都在闭区间[32, 126]内。且行尾没有空格。 这里我们有如下假定:  MOVE操作不超过50000个,INSERT和DELETE操作的总个数不超过4000,PREV和NEXT操作的总个数不超过200000。  所有INSERT插入的字符数之和不超过2M(1M=1024*1024),正确的输出文件长度不超过3M字节。  DELETE操作和GET操作执行时光标后必然有足够的字符。MOVE、PREV、NEXT操作必然不会试图把光标移动到非法位置。  输入文件没有错误。 对C++选手的提示:经测试,最大的测试数据使用fstream进行输入有可能会比使用stdio慢约1秒。

Output

输出文件editor.out的每行依次对应输入文件中每条GET指令的输出。

Sample Input

15

Insert 26

abcdefghijklmnop

qrstuv wxy

Move 16

Delete 11

Move 5

Insert 1

^

Next

Insert 1

_

Next

Next

Insert 4

.\/.

Get 4

Prev

Insert 1

^

Move 0

Get 22

Sample Output

.\/.

abcde^_^f.\/.ghijklmno

Source

NOI2003




#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <ext/rope>

using namespace std;
using namespace __gnu_cxx;

const int maxn=1024*1024*2+10;

crope txt;
char op[10],str[maxn];
int pos=0;

int main()
{
    int T_T,x,y,z;
    scanf("%d",&T_T);
    while(T_T--)
    {
        scanf("%s",op);
        if(op[0]=='M')
        {
            scanf("%d",&pos);
        }
        else if(op[0]=='I')
        {
            scanf("%d",&x);
            y=0;
            while(x)
            {
                char c=getchar();
                if(c>=32&&c<=126)
                {
                    str[y++]=c;
                    x--;
                }
            }
            str[y]=0;
            txt.insert(pos,str);
        }
        else if(op[0]=='D')
        {
            scanf("%d",&x);
            txt.erase(pos,x);
        }
        else if(op[0]=='G')
        {
            scanf("%d",&x);
            puts(txt.substr(pos,x).c_str());
        }
        else if(op[0]=='P') pos--;
        else if(op[0]=='N') pos++;
    }
    return 0;
}



  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值