您的位置:首页 > 其它

1507: [NOI2003]Editor

2016-08-17 15:32 211 查看

1507: [NOI2003]Editor

Time Limit: 5 Sec  Memory Limit: 162 MB
Submit: 3368  Solved: 1343

[Submit][Status][Discuss]

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 15

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

HINT

Source



[Submit][Status][Discuss]

同1269,rope模板,,,
(改改代码就能交两题,谁不喜欢呢?!)
#include<iostream>
#include<cstdio>
#include<queue>
#include<vector>
#include<bitset>
#include<algorithm>
#include<cstring>
#include<map>
#include<stack>
#include<set>
#include<cmath>
#include<ext/rope>
#include<ext/pb_ds/priority_queue.hpp>
using namespace std;
using namespace __gnu_cxx;

const int maxn = 2E6 + 20;

int pos,n,tot;
char A[maxn],ch[20];
rope <char> a,tmp;

int main()
{
#ifdef DMC
freopen("DMC.txt","r",stdin);
#endif

cin >> tot;
while (tot--) {
scanf("%s",ch);
if (ch[0] == 'M') scanf("%d",&pos);
else if (ch[0] == 'I') {
int x,len = a.length(); scanf("%d",&x);
for (int i = 0; i < x; i++) {
A[i] = getchar();
while (A[i] == '\n') A[i] = getchar();
}
A[x] = 0;
a.insert(pos,A);
}
else if (ch[0] == 'D') {
int x,len = a.length(); scanf("%d",&x);
a.erase(pos,x);
}
else if (ch[0] == 'G') {
int x; scanf("%d",&x);
tmp = a.substr(pos,x);
int len = tmp.length();
for (int i = 0; i < len; i++) putchar(tmp[i]);
puts(""); tmp.clear();
}
else if (ch[0] == 'P') --pos;
else ++pos;
}
return 0;
}


内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: