求助,第五和第九个测试点WA
查看原帖
求助,第五和第九个测试点WA
479378
Yungchit楼主2022/5/5 15:32
#include<iostream>
#include<string>
#include<cctype>
using namespace std;

int main()
{
	string title, text;
	int a=-1, ans=0,flag=1,t;

	getline(cin, title);
	getline(cin, text);

	for (int i = 0; i < title.length(); i++)
	{
		title[i] = tolower(title[i]);
	}
	for (int i = 0; i < text.length(); i++)
	{
		text[i] = tolower(text[i]);
	}
	title=" "+title+" ";
	text=" "+text+" ";
	while (text.find(title) != string::npos)
	{
		t = text.find(title);
		if (flag)
		{
			a = t;
			flag = 0;
		}
		ans++;
		text.erase(0,t+1+ title.length());
	}
	if (a != -1)
		cout << ans << " ";
	else
		;
	cout << a <<endl;

	//cout << title << endl;
	//cout << text << endl;

	return 0;
}
2022/5/5 15:32
加载中...