AcWing 3546. 复制、剪切、粘贴
原题链接
简单
作者:
王杜杜
,
2025-01-16 22:50:24
,
所有人可见
,
阅读 1
C++ 代码
#include <string.h>
#include <iostream>
#include <string>
using std::cout;
using std::cin;
using std::endl;
using std::string;
string CUT(const string& original,int l,
int r, string& clipBoard){
string res;
res = original.substr(0,l) + original.substr(r+1);
clipBoard = original.substr(l,r-l+1);
return res;
}
string COPY(const string& original, int l,
int r, string& clipBoard){
clipBoard = original.substr(l,r-l+1);
return original;
}
string PASTE(const string& original, int l,
int r, string& clipBoard){
string res = original.substr(0,l+1)
+ clipBoard
+ original.substr(l+1);
return res;
}
int main()
{
string original;
cin >> original;
int n;
cin >> n;
string clipBoard; // 初始剪切板为空
for(int i = 0; i < n; i++){
string op;
int l;
int r;
cin >> op;
if(op == "CUT"){
cin >> l >> r;
original = CUT(original,l,r,clipBoard);
}else if(op == "COPY"){
cin >> l >> r;
original = COPY(original,l,r,clipBoard);
}else{
cin >> l;
original = PASTE(original,l,r,clipBoard);
}
cout << original << endl;
}
return 0;
}