Цитата:
Сообщение от Света=)
4) Дана строка символов. Необходимо определить в тексте позицию последнего появления определённого слова.
|
Пожалуйста:
Код:
uses crt;
VAR
S,W,Sbef,Saft:String;
cnt,i,W_pos:byte;
BEGIN
Clrscr;
WriteLn('Enter the string:');
ReadLn(S);
WriteLn('Enter the word:');
ReadLn(W);
Repeat
cnt:=pos(W,S);
if cnt>0 then
begin
W_pos:=cnt;
Sbef:=copy(S,1,cnt-1);
Saft:=copy(S,cnt+Length(W),Length(S)-cnt-Length(W)+1);
S:=Sbef;
For i:=1 to Length(W) do
S:=S+'*';
S:=S+Saft;
WriteLn(S);
end;
Until cnt=0;
WriteLn('The last position of the word "'+W+'" is ',W_pos);
ReadLn;
end.