View Code of Problem 3832

#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>

int main(){
	char a[100010];
	char b[100010];
	while(scanf(" %s %s",&a,&b)!=EOF){
		//printf("%s %s\n",a,b);
		if(strstr(a,b)!=NULL){
			int i,j;
			for(i=0,j=0;i<strlen(a)&&j<strlen(b);){
				if(a[i]==b[j]){
					i++;
					j++;
				}else{
					i-=j;
					i++;
					j=0;
				}
			}
			printf("%d\n",i-j+1);
		}else{
			printf("-1\n");
		}
	}
}

				

Double click to view unformatted code.


Back to problem 3832