Tin học - Bài 51: Thay thế từ
Bạn đang xem nội dung tài liệu Tin học - Bài 51: Thay thế từ, để tải tài liệu về máy bạn click vào nút DOWNLOAD ở trên
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;
var
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;
var
f,g:text;
s:string;
i,k:byte;
begin
assign(f,'input1.txt');
reset(f);
assign(g,'kq.out');
rewrite(g);
while not eof(f) do
begin
readln(f,s);
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
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;
begin
init;
replace;
end.
File đính kèm:
De thi Toan Tin hoc trong nha truong Bai 51.doc



