问题标题: 酷町堂:4182 字符串截取,查找,替换 求代码

0
0
已解决
郭梓强
郭梓强
初级光能
初级光能

大家一起找错

#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<string>
#include<iomanip>
#include<algorithm>
#include<cstdlib>
using namespace std;
int main()
{
    string s,c;
    c=s.substr(0,3);
    int p=s.find(3,c);
    if(p==-1)
    {
        cout<<p;
    }
    else
    {
        s.replace(3,p,"cdt");
        cout<<s;
    }
    return 0;
}


0
已采纳
吕梓瑜
吕梓瑜
新手天翼
新手天翼

这题我没有做过,不过我不是来水的,我来给你一个链接,看有么有用~

https://wenda.codingtang.com/questions/15416/?sort=newest

 

吕梓瑜在2021-09-24 18:28:26追加了内容

我做出来了,给你个伪代码~

主函数:
	字符串型变量 s;
	输入s;
	整型变量 x;
	x等于s.find(s.substr(0,3),2);
	如果(x等于等于-1){
		s等于"-1";
	}
	否则{
		s.erase(x,3);
		s.insert(x,"cdt");
	}
	输出s;
    return 0;

 

0
我要回答