WA on #7 求调!
查看原帖
WA on #7 求调!
1137152
SmartCirno楼主2024/4/23 14:06
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int q,t,p; // q:匹配索引(朴素匹配算法),t:匹配次数,p:首次位置
int main()
{
	ios::sync_with_stdio(0);
	string m,s; // m:模式串 
	bool flag=true;
	cin>>m;
	transform(m.begin(),m.end(),m.begin(),::tolower);
	// 直接读取整篇文章 
	cin.ignore();
	getline(cin,s);
	s+=' ';
	for(int i=0;i<s.size();i++)
	{
		if(s[i]==' ')
		{
			if(q==m.size())
			{
				if(t==0)p=i-q,t++;
				q=0;
			}
			flag=true;
		}
		else if(m[q]==tolower(s[i])&&flag)q++;
		else flag=q=0;
	}
	if(t==0)cout<<-1;
	else cout<<t<<" "<<p;
	return 0;
}

2024/4/23 14:06
加载中...