80分求助
查看原帖
80分求助
746322
Rzq122617楼主2025/1/1 19:53
#include<bits/stdc++.h>
using namespace std;
string text,word;
int p,cnt,lenw,p0;
string format(string s)
{
	int len=s.length();
	for(int i=0;i<len;i++)
		if(s[i]>='A'&&s[i]<='Z')s[i]=s[i]+'a'-'A';
	return s;
}
int main(void)
{
	getline(cin,word);
	getline(cin,text);
	word=' '+format(word)+' ';
	text=' '+format(text)+' ';
	p=text.find(word);
	if(p==-1)
	{
		printf("-1");
		return 0;
	}
	lenw=word.length();
	p0=p;
	while(p!=-1)
	{
		p=text.find(word,p+lenw);
		cnt++;
	}
	printf("%d %d",cnt,p0);
	return 0;
}

求调

2025/1/1 19:53
加载中...