#include <stdio.h>
int match(char s1[] , char s2[])
{
int i , j , m , n , r = -1 ;
for(m = 0 ; s1[m] ; m ++) ;
for(n = 0 ; s2[n] ; n ++) ;
if(m >= n && n > 0) {
for(i = 0 ; i < m - n + 1 ; i ++) {
for(j = 0 ; j < n ; j ++) if(s1[i + j] != s2[j]) break ;
if(j == n) {
r = i ;
break ;
}
}
}
return r ;
}
int main(void)
{
char s1[1000000] , s2[1000000] ;
scanf("%s" , s1) ;
scanf("%s" , s2) ;
printf("%d\n" , match(s1 , s2)) ;
}
编译、运行实况:D:\00.Excise\C>g++ -o x x.c
D:\00.Excise\C>x
1234
1234
0
D:\00.Excise\C>x
1234
12345
-1
D:\00.Excise\C>x
821999052039574422
19990520
2
D:\00.Excise\C>x
881994082555083527588321827035
19940825
2
D:\00.Excise\C>
|