Program PascalGuru;
procedure zamena(var s: string; S1, S2: string; var kolvo: integer);
var
N, P: integer;
x: string;
begin
kolvo := 0;
x := '';
N := length(S1);
repeat
P := pos(S1, s);
if P <> 0 then
begin
inc(kolvo);
x := x + copy(s, 1, P - 1) + S2;
delete(s, 1, P + N - 1)
end
until P = 0;
s := x + s;
end;
{ -------------------------------------------- }
var
s, cto, cem: string;
k: integer;
begin
write('Vvedite text: ');
readln(s);
write('Vvedite slovo, kotoroe nado zameniti: ');
readln(cto);
write('Vvedite slovo, kotorym nado zameniti "', cto, '": ');
readln(cem);
writeln;
writeln;
writeln('Isxodnyi text: ', s);
zamena(s, cto, cem, k);
writeln('Preobraz text: ', s);
writeln;
writeln('Kol-vo zamen: ', k);
readln;
end.