2 条题解

  • 3
    @ 2024-1-30 15:47:59
    #include <bits/stdc++.h>
    using namespace std;
    string s,st,sh;//定义变量
    int k;
    int main(){
        getline(cin,s);
        getline(cin,st);
        getline(cin,sh);
        for (int i=0;i<(int)s.size();i++){
            int vf=s.find(st,k);
            if (vf!=-1){
                s.replace(vf,(int)st.size(),sh);
                k+=vf+sh.size();
            }
            else break;
        }
        cout<<s;
        return 0;
    }
    
    • 3
      @ 2023-7-8 10:05:05
      #include <iostream>
      #include <string>
      using namespace std;
      int main() {
      	string a;//在指定串里查找
      	string b;//要查找的串
      	string c;//要替换成的新串
      	getline(cin, a);
      	getline(cin, b);
      	getline(cin, c);
      	//查找指定的串
      	int pos;
      	pos = a.find(b);
      	while (!(pos > a.size())) //如果当find没有找到的话会给到一个很大的数
      	{
      		a.replace(pos, b.length(), c);//用新的串替换掉指定的串
      		pos += c.length();
      		pos = a.find(b, pos);  //从下一个下标pos开始查有没有b字符串,而不是从头开始查
      	}
      	cout << a;
      	return 0;
      }
       
      
      • 1

      信息

      ID
      112
      时间
      1000ms
      内存
      16MiB
      难度
      2
      标签
      递交数
      76
      已通过
      49
      上传者