EQSTR - Biến đổi chuỗi

Tác giả: flashmt

Ngôn ngữ: Pascal

uses math;
var s,a,b:string;
    i,x,y:longint;

function c(x,y:longint):longint;
begin
     if x<y then c:=min(y-x,x+26-y)
     else c:=min(x-y,y+26-x);
end;

procedure pr(x,y:longint);
var i,v,u:longint;
begin
     v:=52;
     for i:=0 to 25 do
         if c(x,i)+c(y,i)<v then
         begin
              v:=c(x,i)+c(y,i);
              u:=i;
         end;
     write(chr(u+97));
end;

begin
     while true do
     begin
          readln(s);
          if s='[END]' then break;
          if s='[CASE]' then
          begin
               readln(a);
               readln(b);
               for i:=1 to length(a) do pr(ord(a[i])-97,ord(b[i])-97);
               writeln;
          end;
     end;
end.

Download