#include <stdio.h> #include <math.h> #include <string.h> int main(){ char str1[100000]; char str2[100000]; while(scanf("%s",str1)!=EOF){ scanf("%s",str2); char *sign=strstr(str1,str2); //strstr是C语言中的函数,作用是返回字符串中首次出现子串的地址。否则,返回NULL。 //printf("%d",sign); if(sign) printf("%d\n",sign-str1+1); //子串的地址-主串的地址+1为相对位置 else{ printf("-1\n"); } } } |
Double click to view unformatted code.