Var a:array[1..30] of integer; i, max, max2:integer; begin for i:= 1 to 30 do read(a[i]); max:=a[1] - 2*a[1];max2:=max; for i:= 1 to 30 do begin if a[i] > max then begin max2:= max; max:=a[i]; continue; end; if a[i] > max2 then max2:=a[i]; end; Writeln(max2, ' ', max); end.
// Внимание! Если программа не работает, обновите версию!
begin
var a:=ArrRandom(30,-50,50); a.Println;
a.OrderByDescending(t->t).Take(2).Println
end.
Пример
14 -16 16 45 -42 27 -47 9 -31 -3 -49 7 15 44 -46 -30 7 34 30 25 -20 45 47 -8 -25 26 -16 42 -5 -17
47 45
a:array[1..30] of integer;
i, max, max2:integer;
begin
for i:= 1 to 30 do
read(a[i]);
max:=a[1] - 2*a[1];max2:=max;
for i:= 1 to 30 do
begin
if a[i] > max then begin
max2:= max;
max:=a[i];
continue;
end;
if a[i] > max2 then
max2:=a[i];
end;
Writeln(max2, ' ', max);
end.