NKEDIT - Hiệu chỉnh văn bản
Tác giả: ll931110
Ngôn ngữ: Pascal
Program NKEDIT;
Const
input = '';
output = '';
Var
k,count: integer;
s1,s2: string;
Procedure init;
Var
f: text;
Begin
Assign(f, input);
Reset(f);
Readln(f, k);
Readln(f, s1);
Readln(f, s2);
Close(f);
End;
Procedure solve;
Var
i,j,pos1,pos2,num: integer;
max,max1,max2: integer;
Begin
count:= 0;
Repeat
max:= 0;
For i:= 1 to length(s1) do
For j:= 1 to length(s2) do if s1[i] = s2[j] then
Begin
pos1:= i;
pos2:= j;
num:= 1;
While (pos1 < length(s1)) and (pos2 < length(s2)) do
Begin
inc(pos1);
inc(pos2);
If s1[pos1] = s2[pos2] then inc(num) else break;
End;
If s1[pos1] <> s2[pos2] then
Begin
dec(pos1);
dec(pos2);
End;
If max < num then
Begin
max:= num;
max1:= pos1 - max + 1;
max2:= pos2 - max + 1;
End;
End;
If max < k then break;
inc(count);
Delete(s1, max1, max);
Delete(s2, max2, max);
Until false;
End;
Procedure printresult;
Var
f: text;
Begin
Assign(f, output);
Rewrite(f);
Writeln(f, count);
Writeln(f, s1);
Writeln(f, s2);
Close(f);
End;
Begin
init;
solve;
printresult;
End.