Editor
| 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#include #include #include #include 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; }