UVA 12538 Version Controlled IDE

本文介绍了一个自动化的IDE版本控制系统,该系统能在程序员进行字符串插入或删除操作时自动保存新版本。文章详细描述了如何通过三种基本命令来管理和检索不同版本的内容,并提供了一段使用ext/rope库实现该系统的示例代码。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

ext/rope 真是持久化字符串处理神器...... 

详见: http://www.sgi.com/tech/stl/Rope.html

UVA - 12538
Version Controlled IDE
Time Limit: 3000MS Memory Limit: Unknown 64bit IO Format: %lld & %llu



12538 Version Controlled IDE
Programmers use version control systems to manage les in their projects, but in these systems, versions
are saved only when you manually submit. Can you implement an IDE that automatically saves a new
version whenever you insert or delete a string?
Positions in the bu er are numbered from 1 from left to right. Initially, the bu er is empty and in
version 0. Then you can execute 3 commands (vnow means the version before executing the command,
and L[v] means the length of bu er at version v):
1 p s: insert string s after position p (0 p L[vnow], p = 0 means insert before the start of the
bu er). s contains at most 1 and at most 100 letters.
2 p c: remove c characters starting at position p (p 1; p + c L[vnow] + 1). The remaining
charactesr (if any) will be shifted left, lling the blank
3 v p c: print c characters starting at position p (p 1; p + c L[v] + 1), in version v (1 v
vnow).
The rst command is guaranteed to be command 1(insert). After executing each command 1 or 2,
version is incremented by 1.
Input
There is only one test case. It begins with a single integer n (1 n 50; 000), the number of commands.
Each of the following n lines contains a command. The total length of all inserted string will not
exceed 1,000,000.
Output
Print the results of command 3, in order. The total length of all printed strings will not exceed 200,000.
Obfuscation:
In order to prevent you from preprocessing the command, we adopt the following obfuscation scheme:
Each type-1 command becomes 1 p + d s
Each type-2 command becomes 2 p + d c + d
Each type-3 command becomes 3 v + d p + d c + d
Where d is the number of lowercase letter `c' you printed, before processing this command.
Before the obfuscation, the sample input would be:
6
1 0 abcdefgh
2 4 3
3 1 2 5
3 2 2 3
1 2 xy
3 3 2 4
This is the real input that your program must process when it reads the Sample Input
below.Universidad de Valladolid OJ: 12538 { Version Controlled IDE 2/2
Sample Input
6
1 0 abcdefgh
2 4 3
3 1 2 5
3 3 3 4
1 4 xy
3 5 4 6
Sample Output
bcdef
bcg
bxyc


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

using namespace std;
using namespace __gnu_cxx;

const int maxn=50500;

crope tmp,var[maxn],t;
int n,op,p,c,v,d,curv;
char str[maxn];

int main()
{
    while(scanf("%d",&n)!=EOF)
    {
        curv=0;d=0;
        while(n--)
        {
            scanf("%d",&op);
            if(op==1)
            {
                scanf("%d%s",&p,str);
                p-=d;
                t.insert(p,str);
                var[++curv]=t;
            }
            else if(op==2)
            {
                scanf("%d%d",&p,&c);
                p-=d;c-=d;
                t.erase(p-1,c);
                var[++curv]=t;
            }
            else if(op==3)
            {
                scanf("%d%d%d",&v,&p,&c);
                v-=d;p-=d;c-=d;
                tmp=var[v].substr(p-1,c);
                d+=count(tmp.begin(),tmp.end(),'c');
                cout<<tmp<<endl;
            }
        }
    }
    return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值