Chinaunix首页 | 论坛 | 博客
  • 博客访问: 753847
  • 博文数量: 265
  • 博客积分: 6010
  • 博客等级: 准将
  • 技术积分: 1985
  • 用 户 组: 普通用户
  • 注册时间: 2009-07-13 12:33
文章分类

全部博文(265)

文章存档

2011年(1)

2010年(66)

2009年(198)

我的朋友

分类: C/C++

2009-10-18 20:07:05

笔试题-两个字符串的最长公共子串
2008-10-21 20:19#include
#include
#include
char * longest(char * a,char *b)
{
int alen=strlen(a);
int blen=strlen(b);
int i,j,index,max=0,num=0;
int start;
for(i=0;i for(j=0;j { int start1=i;
int start2=j;
while((start1<=alen-1) && (start2<=blen-1)&& (a[start1++]==b[start2++]) )
num++;
if(num>max)
{
max=num;
start=i;
}
num=0;
}
for(i=start;i printf("%c",a[i]);
char *str=(char *)malloc(max+1);
//str[max]='/0';
strncpy(str,a+start,max);
}
int main()
{ char a[]="abcdabcdcbadffdaccccafg";
char b[]="gfaccccadffdabcdcbadcba";
longest(a,b);
system("pause");
return 0;


}
阅读(812) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~