Ввести текст и узнать сколько раз в тексте встретится слово story- Pascal(Паскаль)

Пример:
In: A story a story is a book written and illustrated by Gail E. Haley that retells the African tale of now, when there were no stories in the world for children to hear, storystorystor.
Out: 4
uses crt;
const raz=[' ','.',',','?','!'];//разделители слов
var s,sl:string;
    i,k:byte;
begin
clrscr;
writeln('Строка:');
readln(s);
writeln('Слово:');
readln(sl);
k:=0;//количество раз
for i:=1 to length(s) do//идем по строке
if(s[i]=sl[1])and((i=1)or(s[i-1] in raz))//если попалась первая буква слова, а перед ней                                          //разделитель, или она первая
and((s[i+length(sl)] in raz)or(i+length(sl)=length(s)+1))//и за словом разделитель или                                                           //конец строки
and(copy(s,i,length(sl))=sl)//и все буквы совпадают
then k:=k+1;//считаем это слово
write('Слово ',sl,' встречается ',k,' рз.');
readln
end.

Leave a Comment

52 + = 60