30分,求助,谢谢大佬(新手不太会写,望指教)
查看原帖
30分,求助,谢谢大佬(新手不太会写,望指教)
1009837
Lyy1227楼主2023/11/4 11:52
#include<bits/stdc++.h>
using namespace std;
int main()
{
	string f;
	string dc;
	string jz;
	getline(cin,dc);
	getline(cin,jz);
	dc=" "+dc+" ";
	jz=" "+jz+" ";
	int lenj=jz.size();
	int lend=dc.size();
	int cnt=0;
	int wz;
	for(int i=0;i<=lend-1;i++)
	{
		if(dc[i]>='A'&&dc[i]<='Z')
		{
			dc[i]+=32;
		}
	}
	for(int i=0;i<=lend-1;i++)
	{
		if(jz[i]>='A'&&jz[i]<='Z')
		{
			jz[i]+=32;
		}
	}
	for(int i=0;i<=lenj-lend;i++)
	{
		string t="";
		for(int j=i;j<=i+lend-1;j++)
		{
			t+=jz[j];
		}
		if(t==dc)
		{
			cnt++;
			if(cnt==1) wz=i;
		}
	}
	if(cnt==0) cout<<-1;
	else
	{
		cout<<cnt<<" "<<wz;
	}
	return 0;
}
2023/11/4 11:52
加载中...