bzoj 1507: [NOI2003]Editor

使用GNU C++实现文本编辑器
本文介绍了一个简单的文本编辑器程序实现,利用GNU C++的rope库和标准库中的list来模拟一个文本编辑操作的过程。这些操作包括插入、删除、获取等常见编辑功能。
 1 #include<cstdio>
 2 #include<iostream>
 3 #include<ext/rope>
 4 using namespace std;
 5 using namespace __gnu_cxx;
 6 crope list;
 7 int n,now;
 8 char ch[10],ch1[3000005];
 9 int main()
10 {
11     scanf("%d",&n);
12     for(int i=1;i<=n;i++)
13       {
14         int a1;
15         scanf("%s",ch);
16         if(ch[0]!='P'&&ch[0]!='N')
17           scanf("%d",&a1);
18         if(ch[0]=='M')
19           now=a1;
20         if(ch[0]=='I')
21           {
22             for(int i=0;i<a1;i++)
23               {
24                 ch1[i]=getchar();
25                 for(;ch1[i]=='\n';ch1[i]=getchar());
26               }
27             ch1[a1]=0;
28             list.insert(now,ch1);
29            } 
30         if(ch[0]=='D')
31           list.erase(now,a1);
32         if(ch[0]=='G')
33           {
34             list.copy(now,a1,ch1);
35             ch1[a1]=0;
36             printf("%s\n",ch1);
37           }
38         if(ch[0]=='P')
39           now--;
40         if(ch[0]=='N')
41           now++;
42       }
43     return 0;
44 }

本应是个平衡树,偷懒用了list。

转载于:https://www.cnblogs.com/xydddd/p/5271182.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值