NKLETTER - Gửi thư

Tác giả: ll931110

Ngôn ngữ: Pascal

Program NKLETTER;
        Const
                input  = '';
                output = '';
        Var
                s1,s2: string;

Procedure init;
          Var
                f: text;
          Begin
                Assign(f, input);
                        Reset(f);

                Readln(f, s1);
                Readln(f, s2);

                Close(f);
          End;

Procedure solve;
          Var
                f: text;
             max,i,x,y,num: integer;
          Begin
                Assign(f, output);
                        Rewrite(f);

                max:= 0;
                For i:= 1 to length(s1) do if s1[i] = s2[1] then
                        Begin
                                x:= i;
                                y:= 1;
                                num:= 1;

                                While (x < length(s1)) and (y < length(s2)) do
                                        Begin
                                                inc(x);
                                                inc(y);

                                                If s1[x] = s2[y] then inc(num) else break;
                                        End;

                                If x = length(s1) then if max < num then max:= num;
                        End;

                Writeln(f, length(s1) + length(s2) - max);
                Close(f);
          End;

Begin
        init;
        solve;
End.

Download