View Code of Problem 3832

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

}

Double click to view unformatted code.


Back to problem 3832