function IsSeparator(ch: Char): Boolean; begin IsSeparator := (ch = ' ') or (ch = '.') or (ch = ',') or (ch = '!') or (ch = '?'); end;
begin writeln('Enter a sentence: '); readln(sentence);
writeln('Enter a word to search for: '); readln(word);
sentence := sentence + ' '; // add a space at the end to make sure the last word is checked
currentWord := ''; for ch in sentence do begin if not IsSeparator(ch) then currentWord := currentWord + ch else begin if currentWord = word then writeln(sentence); currentWord := ''; end; end; end.
program FindWordsInSentences;
var
sentence, word, currentWord: string;
function IsSeparator(ch: Char): Boolean;
begin
IsSeparator := (ch = ' ') or (ch = '.') or (ch = ',') or (ch = '!') or (ch = '?');
end;
begin
writeln('Enter a sentence: ');
readln(sentence);
writeln('Enter a word to search for: ');
readln(word);
sentence := sentence + ' '; // add a space at the end to make sure the last word is checked
currentWord := '';
for ch in sentence do
begin
if not IsSeparator(ch) then
currentWord := currentWord + ch
else
begin
if currentWord = word then
writeln(sentence);
currentWord := '';
end;
end;
end.