[r]
(1)Bài 51/2001 - Thay từ
(Dành cho học sinh THCS PTTH) program thaythetu;
var
source,des:array[1 50]of string; n:byte;
procedure init; var
i:byte; s:string; f:text; begin
assign(f,'input2.txt'); reset(f);
n:=0;
while not eof(f) begin
readln(f,s); inc(n);
while (s<>'')and(s[1]=' ') 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]=' ') i:=i+1;
source[n]:=copy(s,i,length(s)-i+1); end;
end; end;
procedure replace; var
f,g:text; s:string; i,k:byte; begin
assign(f,'input1.txt'); reset(f);
assign(g,'kq.out'); rewrite(g);
(2)begin
readln(f,s); for k:=1 to n
for i:=1 to length(s)-length(des[k])+1 if des[k]=copy(s,i,length(des[k])) then begin
delete(s,i,length(des[k])); insert(source[k],s,i); i:=i+length(source[k]); end;
writeln(g,s); end;
close(f); close(g); end;