2001 - THAY THẾ TỪ(DÀNH CHO HỌC SINH THCS VÀ PTTH)PROGRAM THAYT...

Bài 51/2001 - Thay thế từ

(Dành cho học sinh THCS và PTTH)

program thaythetu;

var

source,des:array[1..50]of string;

n:byte;

procedure init;

i:byte;

s:string;

f:text;

begin

assign(f,'input2.txt');

reset(f);

n:=0;

while not eof(f) do

begin

readln(f,s);

inc(n);

while (s<>'')and(s[1]=' ') do

delete(s,1,1);

if i>0 then

begin

i:=pos(' ',s);

des[n]:=copy(s,1,i-1);

while (i<=length(s))and(s[i]=' ') do

i:=i+1;

source[n]:=copy(s,i,length(s)-i+1);

end;

end;

end;

procedure replace;

f,g:text;

i,k:byte;

assign(f,'input1.txt');

assign(g,'kq.out');

rewrite(g);

for k:=1 to n do

for i:=1 to length(s)-length(des[k])+1 do

if des[k]=copy(s,i,length(des[k])) then

delete(s,i,length(des[k]));

insert(source[k],s,i);

i:=i+length(source[k]);

writeln(g,s);

close(f);

close(g);

init;

replace;

end.