求救
查看原帖
求救
1511866
Eletronic_Monkey楼主2024/10/17 20:51
#include<stdio.h>
#include<string.h>
#include <stdbool.h>
int main()
{
	char*p,*q;
	char str1[100],str2[10000000];
	bool flag=false;
	gets(str1);
	gets(str2);
	int temp,count=0;
	for(int i=0;i<100;i++)
	{
		if(str1[i]==0)
		{
			break;
		}
		if(str1[i]>=97&&str1[i]<=122)
		{
			str1[i]-=32;
		}
	}
	for(int i=0;i<10000000;i++)
	{
		if(str2[i]==0)
		{
			break;
		}
		if(str2[i]>=97&&str2[i]<=122)
		{
			str2[i]-=32;
		}
	}
	p=str2;
	while(1)
	{
		q=strstr(p,str1);
		if(q==NULL)
		{
			break;
		}
		else
		{
			if(flag==false)
			{
				flag=true;
				temp=(int)(q-&str2[0]);
			}
			count++;
			p+=strlen(str1);
		}
	}
	if(flag==true)
	{
		printf("%d %d",count,temp);
	}
	else
	{
		printf("-1");
	}
	return 0;
}

2024/10/17 20:51
加载中...