蒟蒻80pts求调(WA 5,9)
查看原帖
蒟蒻80pts求调(WA 5,9)
836643
Asher12楼主2024/10/16 23:29

5,9 WA

#include <iostream>
#include <cctype>
#include <cstdio>
using namespace std;
int main()
{
//	freopen("stat.in","r",stdin);
//	freopen("stat.out","w",stdout);
	ios::sync_with_stdio(false);
	cin.tie(0);
	string str,text;
	cin>>str;
	cin.get();
	getline(cin,text);
	for (int i=0;i<str.size();i++)
	{
		str[i]=tolower(str[i]);
	}
	for (int i=0;i<text.size();i++)
	{
		text[i]=tolower(text[i]);
	}
	str=" "+str;
	str+=" ";
	text=" "+text;
	text+=" ";
	int cnt=0,ans=0;
	int x=0;
	while (text.find(str,x)!=string::npos)
	{
		++cnt;
		if (cnt==1)
		{
			ans=text.find(str,x);
		}
		x=text.find(str,x)+str.size()+1;
		if (x>text.size())
		{
			break;
		}
	}
	if (cnt!=0)
	{
		cout<<cnt<<' '<<ans<<'\n';
	}
	else
	{
		cout<<-1<<'\n';
	}
	return 0;
}
2024/10/16 23:29
加载中...