program CountWordsStartingWithA; var sentence: string; wordsCount, i: integer; word: string; delimiter: char; words: array of string; begin wordsCount := 0; writeln('Введите предложение:'); readln(sentence); delimiter := ' '; SetLength(words, 0); repeat i := pos(delimiter, sentence); if i = 0 then i := length(sentence) + 1; word := copy(sentence, 1, i-1); delete(sentence, 1, i); if (length(word) > 0) and (word[1] = 'a') then begin wordsCount := wordsCount + 1; SetLength(words, length(words) + 1); words[length(words) - 1] := word; end; until i = length(sentence) + 1; writeln('Количество слов, начинающихся с буквы ''a'': ', wordsCount); writeln('Слова:'); for i := 0 to length(words) - 1 do writeln(words[i]); end.
Пример программы на Pascal:
program CountWordsStartingWithA;var
sentence: string;
wordsCount, i: integer;
word: string;
delimiter: char;
words: array of string;
begin
wordsCount := 0;
writeln('Введите предложение:');
readln(sentence);
delimiter := ' ';
SetLength(words, 0);
repeat
i := pos(delimiter, sentence);
if i = 0 then
i := length(sentence) + 1;
word := copy(sentence, 1, i-1);
delete(sentence, 1, i);
if (length(word) > 0) and (word[1] = 'a') then
begin
wordsCount := wordsCount + 1;
SetLength(words, length(words) + 1);
words[length(words) - 1] := word;
end;
until i = length(sentence) + 1;
writeln('Количество слов, начинающихся с буквы ''a'': ', wordsCount);
writeln('Слова:');
for i := 0 to length(words) - 1 do
writeln(words[i]);
end.