/* 你会读到两个字符串,每个字符串占据一行,每个字符串的长度均小于10000字符,而且第一个字符串的长度小于第二个字符串的。
你的程序要找出第一个字符串在第二个字符串中出现的位置,输出这些位置,如果找不到,则输出-1。 */
#include <stdio.h>
#include <string.h>
#define MAXZISE 10000
int pos( char *b , char *a)
{
char *s = a;//记录a初始位置
char *t = b;//记录b初始位置
char *u = NULL;//记录A与B相等时的B的初始位置
int value = 1;
while ( *b )
{
if ( *a != *b)
{//如果A与B不等,则重置A的位置
a = s ;
if ( *a != *b )
{//重置A的位置后,A扔不等于B,将B+1;
a = s;
b++;
}
}
else
{
u = b;//记录A=B的起始位置
while ( *a == *b )
{//如果A与B相等,则判断直到A结束与B是否相等
a++;
b++;
if ( *a == '\0')
{
b = b - 1;
printf("%d ",u - t);
value = 0;
a = s;
break ;
}
}
}
}
if ( value )
printf("%d ", -1 );
}
int main ()
{
char a[MAXZISE];
char b[MAXZISE];
gets (a);
gets (b)
pos ( b ,a );
return 0;
}