program MaxAsciiDiff;
function MaxAsciiDiff(const s: string; var c1, c2: char): Integer;
var
i, diff, maxDiff: Integer;
begin
if Length(s) < 2 then
begin
MaxAsciiDiff := 0;
Exit;
end;
maxDiff := 0;
for i := 1 to Length(s) - 1 do
begin
diff := Abs(Ord(s[i]) - Ord(s[i + 1]));
if diff > maxDiff then
begin
maxDiff := diff;
c1 := s[i];
c2 := s[i + 1];
end;
end;
MaxAsciiDiff := maxDiff;
end;
var
s: string;
a, b: char;
resultValue: Integer;
begin
s := 'jumplings';
a := #0;
b := #0;
resultValue := MaxAsciiDiff(s, a, b);
WriteLn('Maximum ASCII difference: ', resultValue);
WriteLn('Characters: ''', a, ''' and ''', b, '''');
end.
(*
run:
Maximum ASCII difference: 12
Characters: 'g' and 's'
*)