# include <stdio.h>
# include <string.h>
# define MAX 20
void main()
{
void search_s(char *s1,char *s2);
char s1[MAX],s2[MAX];
printf("please input string 1:\n");
gets(s1);
printf("please input string 2:\n");
gets(s2);
search_s(s1,s2);
}
void search_s(char *s1,char *s2) //记录相同字符串
{
int print_s(int *s1,int *s2,int p);
int i,j,s=strlen(s1),t=strlen(s2);
int s3[MAX]={0},s4[MAX],p=0,k;
int d;
for(i=0;i<s;i++)
{
for(j=0;j<t;j++)
if(s1[i]==s2[j])
{
s4[p]=i; //记录相同字符串起始字符位置
s3[p]=1;p++;//记录连续相同字符个数
for(k=1;s1[i+k] && s2[j+k];k++)
{
if(s1[i+k]==s2[j+k])
s3[p-1]=s3[p-1]+1;
}
}
}
d=print_s(s3,s4,p);
for(i=s4[d];i<s4[d]+s3[d];i++)
printf("%c",s1[i]);
printf("\n");
}
int print_s(int *s1,int *s2,int p) //找到打印位置
{
int i,max=s1[0],k;
for(i=1;i<p;i++)
{
if(max<s1[i])
{
max=s1[i];
k=i;
}
}
return k;
}