#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define MAXN 9999
int num[MAXN][MAXN];
int step[MAXN][MAXN];
char res[MAXN];
void get_lcs(char s1[],char s2[],int i,int j){
int m = num[j][i]-1;
while(i>=0&&j>=0){
if(step[j][i]==0){
res[m--] = s1[i];
i--;
j--;
}
else if(step[j][i] == -1)
i--;
else
j--;
}
}
int calc_lcs(char s1[],char s2[],int i,int j){
if (i==-1 || j==-1)
return 0;
if (num[j][i]>-1)
return num[j][i];
int n1,n2,n;
if(s1[i] == s2[j]){
n = calc_lcs(s1,s2,i-1,j-1);
step[j][i] = 0;
num[j][i] = n+1;
return n+1;
}
else{
n1 = calc_lcs(s1,s2,i-1,j);
n2 = calc_lcs(s1,s2,i,j-1);
if(n1>n2){
step[j][i] = -1;
num[j][i] = n1;
return n1;
}
else{
step[j][i] = 1;
num[j][i] = n2;
return n2;
}
}
}
double calc(char s1[],char s2[]){
int len1,len2,i,j;
len1 = strlen(s1);
len2 = strlen(s2);
for(j=0;j<len2;j++)
for(i=0;i<len1;i++){
num[j][i] = -1;
step[j][i] = 9;
}
//int l = num[len2-1][len1-1];
int l = calc_lcs(s1,s2,len1-1,len2-1);
int shorter = (len1 < len2 ? len1 : len2);
double percent = (double)l/(double)shorter;
return percent;
}
int main(){
/*
*
fgets(s1,MAXN,file);
fgets(s2,MAXN,file);
*/
/*
char s1[] = "asdf";
char s2[] = "aqweqwedqrqef";
*/
char s1[MAXN];
char s2[MAXN];
FILE *instream;
instream = freopen("text","r",stdin);
if (instream == NULL)
fprintf(stderr,"freopen failed!!!!!!!!!");
gets(s1);
gets(s2);
fclose(stdin);
instream = NULL;
double p = calc(s1,s2);
printf("%s\n",s1);
printf("%s\n",s2);
printf("%f\n",p);
return 0;
}
08-25