CHATCHIT - Chat chit

Tác giả: ladpro98

Ngôn ngữ: Pascal

program chatchit;
uses    math;
const   fi='';
var     res:ansistring;

procedure rw(x,y:string);
var     i:longint;
        t:ansistring;
begin
        t:='';
        i:=1;
        while i<=length(res) do
        begin
        if res[i] in ['a'..'z'] then
                t:=t+res[i]
        else
        if (i+length(x)<length(res)) and not (res[i+length(x)+1] in ['a'..'z']) and (copy(res,i+1,length(x))=x) then
                begin
                        t:=t+res[i]+y;
                        inc(i,length(x));
                end
                else
                t:=t+res[i];
        inc(i);
        end;
        res:=t;
end;

procedure r(x,y:string);
var     i:longint;
        t:ansistring;
begin
        i:=1;
        t:='';
        while i<=length(res) do
        begin
        if copy(res,i,length(x))=x then
        begin
                t:=t+y;
                inc(i,length(x)-1);
        end
        else t:=t+res[i];
        inc(i);
        end;
        res:=t;
end;

procedure input;
var     inp:text;
begin
        assign(inp,fi);
        reset(inp);
        readln(inp,res);
        close(inp);
end;

begin
        input;
        res:=' '+res+' ';
        rw('k','khong');
        rw('ko','khong');
        rw('ng','nguoi');
        rw('n','nhieu');
        rw('dc','duoc');
        rw('hok','khong');
        rw('ntn','nhu the nao');
        rw('kq','ket qua');
        r('j','gi');
        r('w','qu');
        r('f','ph');
        r('dz','d');
        r('z','d');
        write(copy(res,2,length(res)-1));
end.

Download