fork download
  1. program ideone;
  2.  
  3. Const smax = 99;
  4. Type simple = array[0..smax] of smallint;
  5. Var data:simple; i, n, indMax1, indMax2, indMin1, indMin2:smallint;
  6.  
  7. procedure writeArr(data:simple);
  8. Var i:smallint;
  9. begin
  10. for i:=0 to n-1 do write(data[i], ' ');
  11. writeln();
  12. end;
  13.  
  14. function bubbleSort(data:simple):simple;
  15. Var i, j, t:smallint;
  16. begin
  17. for i:=0 to n-1 do
  18. for j:=0 to n-2 do
  19. if data[j]>data[j+1] then begin
  20. t:=data[j];
  21. data[j]:=data[j+1];
  22. data[j+1]:=t;
  23. end;
  24. bubbleSort:=data;
  25. end;
  26.  
  27. procedure distance(data:simple);
  28. Var i, j:smallint; sort:simple;
  29. begin
  30. sort:=bubbleSort(data);
  31. writeArr(sort);
  32. writeln('=========');
  33. for i:=0 to n-2 do begin
  34. for j:=i+1 to n-1 do
  35. if abs(data[i]-data[j])<abs(data[indMin1]-data[indMin2]) then begin
  36. indMin1:=i;
  37. indMin2:=j;
  38. end;
  39.  
  40. if abs(sort[i]-sort[i+1])>abs(sort[indMax1]-sort[indMax1+1]) then begin
  41. indMax1:=i;
  42. indMax2:=i+1;
  43. end;
  44. end;
  45. end;
  46.  
  47. begin
  48. indMax1:=0;
  49. indMax2:=1;
  50. indMin1:=0;
  51. indMin2:=1;
  52.  
  53. read(n);
  54. for i:=0 to n-1 do read(data[i]);
  55.  
  56. distance(data);
  57. writeln(abs(data[indMax1]-data[indMax2]), ' ', indMax1+1, ' ', indMax2+1);
  58. writeln(abs(data[indMin1]-data[indMin2]), ' ', indMin1+1, ' ', indMin2+1);
  59. end.
Success #stdin #stdout 0.01s 5280KB
stdin
8
4 5 2 20 3 16 6 18
stdout
2 3 4 5 6 16 18 20 
=========
13 5 6
1 1 2