59
правок
Изменения
Нет описания правки
|'''h''' ||'''e''' ||'''l''' ||'''l''' ||'''o''' ||'''2''' ||'''1''' ||'''4'''
|}
== код получения редакторского предписания ==
readln(s1);
readln(s2);
n := length(s1);
m := length(s2);
for i := 1 to n do d[0, i] := i;
for i := 1 to m do d[i, 0] := i;
for i := 1 to n do for j := 1 to m do
if s1[i] = s2[j] then
begin
d[i, j] := d[i - 1, j - 1];
p[i, j].x := i - 1;
p[i, j].y := j - 1;
end else
begin
if (d[i - 1, j] <= d[i, j - 1])and(d[i - 1, j] <= d[i - 1, j - 1]) then
begin
d[i, j] := d[i - 1, j] +1;
p[i, j].x := i - 1;
p[i, j].y := j;
end;
if (d[i, j - 1] <= d[i - 1, j])and(d[i, j - 1] <= d[i - 1, j - 1]) then
begin
d[i, j] := d[i, j - 1] +1;
p[i, j].x := i;
p[i, j].y := j - 1;
end;
if (d[i - 1, j - 1] <= d[i, j - 1])and(d[i - 1, j - 1] <= d[i - 1, j]) then
begin
d[i, j] := d[i - 1, j - 1] + 1;
p[i, j].x := i - 1;
p[i, j].y := j - 1;
end;
end;
x := n;
y := m;
while (x > 0) and (y > 0) do
begin
if p[x, y].x - x = 0 then s := 'D' + s else
if p[x, y].y - y = 0 then s := 'I' + s else
if s1[x] = s2[y] then s := 'M' + s else s := 'R' + s;
x := p[x, y].x;
y := p[x, y].y;
end;
writeln(s);