В Паскале! Ввести с клавиатуры строку и определить в ней максимальную серию символов, отличных от букв.

18 Янв 2020 в 19:41
128 +1
0
Ответы
1
program MaxNonLetterSeries;
var
str: string;
i, count, maxCount: integer;
prevIsLetter, currentIsLetter: boolean;
maxNonLetterSeries: string;
begin
writeln('Введите строку:');
readln(str);
count := 0;
maxCount := 0;
maxNonLetterSeries := '';
prevIsLetter := false;
for i := 1 to length(str) do
begin
if not (str[i] in ['A'..'Z', 'a'..'z']) then
begin
count := count + 1;
currentIsLetter := false;
end
else
begin
if count > maxCount then
begin
maxCount := count;
maxNonLetterSeries := copy(str, i - count, count);
end;
count := 0;
currentIsLetter := true;
end;
if not currentIsLetter and not prevIsLetter then
begin
count := 1;
end;
prevIsLetter := currentIsLetter;
end;
if count > maxCount then
begin
maxCount := count;
maxNonLetterSeries := copy(str, length(str) - count + 1, count);
end;
writeln('Максимальная серия символов, отличных от букв: ', maxNonLetterSeries);
end.

Пример работы программы:

Введите строку:
abc123ab!@#$@
Максимальная серия символов, отличных от букв: !@#$
18 Апр 2024 в 19:47
Не можешь разобраться в этой теме?
Обратись за помощью к экспертам
Гарантированные бесплатные доработки в течение 1 года
Быстрое выполнение от 2 часов
Проверка работы на плагиат
Поможем написать учебную работу
Прямой эфир