Advertisement
leminhkt

72

Aug 5th, 2020
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 0.70 KB | None | 0 0
  1. const M = 1000000;
  2. var i, n, min, premin, max, premax: longint;
  3.     a: array[1..M] of longint;
  4. begin
  5.     read(n);
  6.     for i := 1 to n do
  7.         read(a[i]);
  8.  
  9.     min := M; premin := M;
  10.     max := -M; premax := -M;
  11.     for i := 1 to n do begin
  12.         if a[i] < min then begin
  13.             premin := min;
  14.             min := a[i];
  15.         end
  16.         else if a[i] < premin then
  17.             premin := a[i];
  18.         if a[i] > max then begin
  19.             premax := max;
  20.             max := a[i];
  21.         end
  22.         else if a[i] > premax then
  23.             premax := a[i];
  24.     end;
  25.    
  26.     write('premin = ', premin, ', index = ');
  27.     for i := 1 to n do
  28.         if a[i] = premin then
  29.             write(i, ' ');
  30.     writeln;
  31.     write('premax = ', premax, ', index = ');
  32.     for i := 1 to n do
  33.         if a[i] = premax then
  34.             write(i, ' ');
  35. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement