UVA 1207 Solution -AGTC
/* Solved by using Edit-Distance Algorithm*/
/*
uva id- shoaib05
Accpted Time: 0.001
*/
#include<stdio.h>
#include<algorithm>
#include<iostream>
using namespace std;
char x[5010],y[5010];
int len1,len2,table[5010][5010];
void buildTable()
{
int i,j;
for(i=0;i<=len1;i++)
table[i][0]=i;
for(j=0;j<=len2;j++)
table[0][j]=j;
for(i=1;i<=len1;i++)
{
for(j=1;j<=len2;j++)
{
if(x[i-1]==y[j-1])
table[i][j]=table[i-1][j-1];
else
table[i][j]=min(table[i-1][j-1],min(table[i-1][j],table[i][j-1]))+1;
}
}
}
int main()
{
while(scanf("%d %s %d %s",&len1,x,&len2,y)==4)
{
buildTable();
printf("%d\n",table[len1][len2]);
}
return 0;
}
Comments
Post a Comment