View Code of Problem 3832

#include<stdio.h>
#include<string.h>
int main()
{
	char a[1000000];
	char b[1000000];
	while(scanf("%s%s",a,b)!=EOF)
	{
		
		int i,j,k;
		for(i=0;i<strlen(a)-strlen(b)+1;i++)
		{
			k=i;
			j=0;
			while(a[k]==b[j]&&a[k]!=0)
			{
				k++;
				j++;
			}
			if(j==strlen(b))
			{
				break;
			}
		}
		if(i>=strlen(a)-strlen(b)+1) printf("-1\n");
		else printf("%d\n",i+1);
	}
}

Double click to view unformatted code.


Back to problem 3832