题目描述
你需要开发一款文字处理软件。最开始时输入一个字符串(不超过 100 个字符)作为初始文档。可以认为文档开头是第 0 个字符。需要支持以下操作:
1 str:后接插入,在文档后面插入字符串 str,并输出文档的字符串。
2 a b:截取文档部分,只保留文档中从第 a 个字符起 b 个字符,并输出文档的字符串。
3 a str:插入片段,在文档中第 a 个字符前面插入字符串 str,并输出文档的字符串。
4 str:查找子串,查找字符串 str 在文档中最先的位置并输出;如果找不到输出 -1。
为了简化问题,规定初始的文档和每次操作中的 str 都不含有空格或换行。最多会有 q(q\le100)q(q≤100) 次操作。
输入格式
无
输出格式
无
输入输出样例
输入 #1 复制
4
ILove
1 Luogu
2 5 5
3 3 guGugu
4 gu
输出 #1 复制
ILoveLuogu
Luogu
LuoguGugugu
3
题目连接在此
#include <iostream>
#include <cstring>
#include <math.h>
#include <string.h>
void weicha(std::string basicString, std::string *pString);
using namespace std;
int main() {
string s;
string stemp;
int opnum;
int n;
cin>>n;//进行操作的数量
cin>>s;//待操作字符串
int a,b;
for(int i=0;i<n;i++){
cin>>opnum;
//尾插
if(opnum==1){
cin>>stemp;
s=s+stemp;
cout<<s<<endl;
}
//截取
if(opnum==2){
cin>>a>>b;
//cout<<s.substr(a,b)<<endl;
stemp=s.substr(a,b);
s=stemp;
cout<<s<<endl;
}
//插入片段
if(opnum==3){
cin>>a;
cin>>stemp;
s.insert(a,stemp);
cout<<s<<endl;
}
//查找字串
if(opnum==4){
cin>>stemp;
int pis=s.find(stemp);
/* if(pis<0||pis>=stemp.length())
pis=-1;*/
cout<<pis<<endl;
}
}
return 0;
}