记录编号 |
12692 |
评测结果 |
AAAAAAAAAA |
题目名称 |
字符串的距离 |
最终得分 |
100 |
用户昵称 |
ybh |
是否通过 |
通过 |
代码语言 |
Pascal |
运行时间 |
0.675 s |
提交时间 |
2009-09-18 19:12:11 |
内存使用 |
15.39 MiB |
显示代码纯文本
program LABST;
const
max=2000;
var
a,b:array[0..max] of char;
f:array[0..max,0..max] of longint;
n,la,lb,i,j,cost:longint;
begin
assign(input,'blast.in');
assign(output,'blast.out');
reset(input);
rewrite(output);
la:=0;
lb:=0;
while not eoln do
begin
inc(la);
read(a[la]);
end;
readln;
while not eoln do
begin
inc(lb);
read(b[lb]);
end;
readln;
readln(cost);
fillchar(f,sizeof(f),100);
for i:=0 to la do
f[i,0]:=i*cost;
for i:=0 to lb do
f[0,i]:=i*cost;
for i:=1 to la do
for j:=1 to lb do
begin
f[i,j]:=f[i-1,j-1]+abs(ord(a[i])-ord(b[j]));
if f[i,j]>f[i-1,j]+cost
then f[i,j]:=f[i-1,j]+cost;
if f[i,j]>f[i,j-1]+cost
then f[i,j]:=f[i,j-1]+cost;
end;
writeln(f[la,lb]);
close(input);
close(output);
end.