文章

6

粉丝

16

获赞

1

访问

1.3k

头像
字符串替换 题解:
P2011
发布于2024年3月26日 19:20
阅读数 175

看不懂的话就用双重循环吧~,如果有多个tantan,

#include <bits/stdc++.h>
using namespace std;

int main()
{
	string s;
	string sp = "baibai";
	bool isExact = false;
	cin>>s;
	for(auto &ss : s){
		ss = tolower(ss);
	}
    //Find the all position of "tantan"
	for(int i = 0;i < s.size();i++){
		for(int j = 0;j < s.size();j++){
			if(s.substr(i, j - i + 1) == "tantan"){
				isExact = true;
				for(int k = i;k <= j;k++){
					s[k] = sp[k-i];
				}
			}
		}
	}
	if(isExact){
		cout<<s<<endl;
	}
	else{
		cout<<"not find"<<endl;
	}
	return 0;
}

 

登录查看完整内容


登录后发布评论

暂无评论,来抢沙发