20分求助
查看原帖
20分求助
746322
Rzq122617楼主2024/12/14 23:22
#include<bits/stdc++.h>
using namespace std;
string word,text;
int cnt,len1,len2;
void tosmall(string s)
{
	int len=s.size();
	for(int i=0;i<len;i++)s[i]=tolower(s[i]);
}
int main(void)
{
	getline(cin,word); 
	word=' '+word+' ';
	getline(cin,text);
	text=' '+text+' ';
	tosmall(text);
	tosmall(word);
	len1=word.size();
	len2=text.size();
	int pos=text.find(word);
	if(pos==-1)
	{
		printf("-1");
		return 0;
	}
	while(pos!=-1)
	{
		pos=text.find(word,pos+len1-1);
		cnt++;
	}
	printf("%d",cnt);
	//cout<<endl<<word;
	return 0;
}

求助,怎么过不了

2024/12/14 23:22
加载中...