fork download
  1. program ideone;
  2.  
  3. Const smax = 99;
  4. Type simple = array[0..smax] of smallint;
  5. Var data, sort: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. function getIndex(arr:simple; num:smallint):smallint;
  28. Var i:smallint;
  29. begin
  30. i:=0;
  31. while (arr[i]<>num) and (i<n) do i:=i+1;
  32. getIndex:=i;
  33. end;
  34.  
  35. procedure distance(data, sort:simple);
  36. Var i, j, indMaxS1, indMaxS2:smallint;
  37. begin
  38. indMaxS1:=0;
  39. indMaxS2:=1;
  40. for i:=0 to n-2 do begin
  41. for j:=i+1 to n-1 do
  42. if abs(data[i]-data[j])<abs(data[indMin1]-data[indMin2]) then begin
  43. indMin1:=i;
  44. indMin2:=j;
  45. end;
  46.  
  47. if abs(sort[i]-sort[i+1])>abs(sort[indMaxS1]-sort[indMaxS2]) then begin
  48. indMaxS1:=i;
  49. indMaxS2:=i+1;
  50. end;
  51. end;
  52.  
  53. indMax1:=getIndex(data, sort[indMaxS1]);
  54. indMax2:=getIndex(data, sort[indMaxS2]);
  55. end;
  56.  
  57. begin
  58. indMax1:=0;
  59. indMax2:=1;
  60. indMin1:=0;
  61. indMin2:=1;
  62.  
  63. read(n);
  64. for i:=0 to n-1 do read(data[i]);
  65.  
  66. sort:=bubbleSort(data);
  67.  
  68. distance(data, sort);
  69. writeln(abs(data[indMin1]-data[indMin2]), ' ', indMin1+1, ' ', indMin2+1);
  70. writeln(abs(data[indMax1]-data[indMax2]), ' ', indMax1+1, ' ', indMax2+1);
  71. end.
Success #stdin #stdout 0s 5284KB
stdin
9
5 18 10 2 9 -1 -16 15 8
stdout
1 3 5
15 7 6