Дана строка, состоящая из слов, разделённая пробелами и запятыми, определить длину самого короткого и самого длинного слова.Написать программу в Pascal.
function GetLongestWordLength(s: string): Integer; var maxLen, currLen: Integer; i: Integer; begin maxLen := 0; currLen := 0;
for i := 1 to Length(s) do begin if (s[i] <> ' ') and (s[i] <> ',') then begin currLen := currLen + 1; end else begin if currLen > maxLen then maxLen := currLen;
currLen := 0; end;
end;
if currLen > maxLen then maxLen := currLen;
GetLongestWordLength := maxLen; end;
function GetShortestWordLength(s: string): Integer; var minLen, currLen: Integer; i: Integer; begin minLen := High(Integer); currLen := 0;
for i := 1 to Length(s) do begin if (s[i] <> ' ') and (s[i] <> ',') then begin currLen := currLen + 1; end else begin if currLen < minLen then minLen := currLen;
currLen := 0; end;
end;
if currLen < minLen then minLen := currLen;
GetShortestWordLength := minLen; end;
var inputStr: string; longestWordLen, shortestWordLen: Integer; begin Write('Введите строку: '); Readln(inputStr);
program LongestShortestWord;
function GetLongestWordLength(s: string): Integer;
var
maxLen, currLen: Integer;
i: Integer;
begin
maxLen := 0;
currLen := 0;
for i := 1 to Length(s) do
currLen := 0;begin
if (s[i] <> ' ') and (s[i] <> ',') then
begin
currLen := currLen + 1;
end
else
begin
if currLen > maxLen then
maxLen := currLen;
end;
end;
if currLen > maxLen then
maxLen := currLen;
GetLongestWordLength := maxLen;
end;
function GetShortestWordLength(s: string): Integer;
var
minLen, currLen: Integer;
i: Integer;
begin
minLen := High(Integer);
currLen := 0;
for i := 1 to Length(s) do
currLen := 0;begin
if (s[i] <> ' ') and (s[i] <> ',') then
begin
currLen := currLen + 1;
end
else
begin
if currLen < minLen then
minLen := currLen;
end;
end;
if currLen < minLen then
minLen := currLen;
GetShortestWordLength := minLen;
end;
var
inputStr: string;
longestWordLen, shortestWordLen: Integer;
begin
Write('Введите строку: ');
Readln(inputStr);
longestWordLen := GetLongestWordLength(inputStr);
shortestWordLen := GetShortestWordLength(inputStr);
WriteLn('Самое длинное слово имеет длину: ', longestWordLen);
WriteLn('Самое короткое слово имеет длину: ', shortestWordLen);
end.