AcWing 3546. 复制、剪切、粘贴
原题链接
简单
作者:
深远栗川
,
2021-05-22 16:57:18
,
所有人可见
,
阅读 229
#include<iostream>
#include<cstring>
#define maxn 10010
using namespace std;
char s[maxn];
char t[maxn];
char tmp[maxn];
char op[15];
int main()
{
int m,i;
int l,r,p;
while(cin>>s)
{
cin>>m;
strcpy(t,"");
while(m--)
{
cin>>op;
if(strcmp(op,"COPY")==0)
{
cin>>l>>r;
for(i=l; i<=r; i++)
{
tmp[i-l]=s[i];
}
tmp[r-l+1]='\0';
strcpy(t,tmp);
cout<<s<<endl;
}
else if(strcmp(op,"CUT")==0)
{
cin>>l>>r;
for(i=l; i<=r; i++)
{
tmp[i-l]=s[i];
}
tmp[r-l+1]='\0';
strcpy(t,tmp);
strcpy(tmp,"");
int len1=strlen(s);
int len2=r-l+1;
for(i=0; i<l; i++)
tmp[i]=s[i];
for(i=l; i<len1-len2; i++)
tmp[i]=s[i+len2];
tmp[i]='\0';
strcpy(s,tmp);
cout<<s<<endl;
}
else
{
cin>>p;
int len1=strlen(s);
int len2=strlen(t);
for(i=0; i<=p; i++)
tmp[i]=s[i];
for(i=p+1; i<=p+len2; i++)
tmp[i]=t[i-p-1];
for(i=p+1+len2; i<len1+len2; i++)
tmp[i]=s[i-len2];
tmp[i]='\0';
strcpy(s,tmp);
cout<<s<<endl;
}
}
}
return 0;
}
----------