| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
help!!!!! 真的假的这代码过不去吗???????????????????#include <stdio.h>
#include <string.h>
#define N 100
int lcs_len(char *a,char *b, int c[][N])
{
int m=strlen(a),n=strlen(b),i,j;
for(i=0;i<=m;i++)
c[i][0]=0;
for(j=0;j<=n;j++)
c[0][j]=0;
for(i=1;i<=m;i++)
for(j=1;j<=n;j++)
{
if (a[i-1]==b[j-1])
c[i][j]=c[i-1][j-1]+1;
else if(c[i-1][j]>=c[i][j-1])
c[i][j]=c[i-1][j];
else
c[i][j]=c[i][j-1];
}
return c[m][n];
}
int build_lcs(char *s,char *a,char *b)
{
int k,i=strlen(a),j=strlen(b),c[N][N];
k=lcs_len(a,b,c);
s[k]='\0';
while(k>0)
if(c[i][j]==c[i-1][j])
i--;
else if(c[i][j]==c[i][j-1])
j--;
else
{
s[--k]=a[i-1];
i--;
j--;
}
return strlen(s);
}
void main()
{
int i,n;
char a[N],b[N],str[N];
scanf("%d",&n);
scanf("%s",a);
scanf("%d",&n);
scanf("%s",b);
printf("%d\n",strlen(b)-build_lcs(str,a,b));
}
Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator