#include<stdio.h> #include<string.h> int main(){ char a[100000]; char b[100000]; while(scanf("%s",a)!=EOF){ scanf("%s",b); if(strlen(a)<strlen(b)){ printf("-1\n"); } else if(strlen(a)==strlen(b)){ if(strcmp(a,b)==0) printf("1\n"); else printf("-1\n"); } else if(strlen(a)>strlen(b)){ int i,j,len1,len2; len1=strlen(a); len2=strlen(b); for(i=0;i<=len1-len2;i++){ for(j=0;j<len2;j++){//在匹配过程中有一个不对就停止 if(a[i+j]!=b[j]) break; } if(j==len2)//全部匹配成功 break; } if(i<=len1-len2){ printf("%d\n",i+1); } else printf("-1\n"); } } return 0; } |
Double click to view unformatted code.