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