代码求调
  • 板块灌水区
  • 楼主yqcg
  • 当前回复2
  • 已保存回复2
  • 发布时间2023/5/28 10:32
  • 上次更新2023/10/23 14:30:42
查看原帖
代码求调
825994
yqcg楼主2023/5/28 10:32

rt

题目为P5734 【深基6.例6】文字处理软件

本地测试没有问题,可是错了三个测试点,对了两个

代码如下:

#include<bits/stdc++.h>

using namespace std;

int main(){
	int q,a;
	string s;
	cin>>q;
	scanf("\n");
	getline(cin,s);
	for(int i=0;i<q;i++){
		cin>>a;
		if(a==1){
			string str;
			cin>>str;
			s=s+str;
			cout<<s<<endl;
		}else if(a==2){
			string str;
			int x,y;
			cin>>x>>y;
			s=s.substr(x,y);
			cout<<s<<endl;
		}else if(a==3){
			string str;
			int a;
			cin>>a;
			cin>>str;
			s=s.insert(a,str);
			cout<<s<<endl;
		}else if(a==4){
			string str;
			cin>>str;
			if(s.find(str)==string::npos){
				cout<<-1<<endl;
			}else{
				cout<<s.find(str)<<endl;
			}
		}
	}
	return 0;
}
2023/5/28 10:32
加载中...