fork download
  1. program ideone;
  2.  
  3. Const smax = 99;
  4. Type simple = array[0..smax] of smallint;
  5. Var data, res:simple; i, n:smallint;
  6.  
  7. procedure writeArr(arr:simple);
  8. Var i:smallint;
  9. begin
  10. for i:=0 to n-1 do write(arr[i], ' ');
  11. writeln();
  12. end;
  13.  
  14. function isSame(arr:simple; num:smallint):boolean;
  15. Var i:smallint;
  16. begin
  17. i:=0;
  18. while (i<n) and (arr[i]<>num) do i:=i+1;
  19. if i=n then isSame:=False else isSame:=True;
  20. end;
  21.  
  22. function converter(data:simple):simple;
  23. Var i, j, index, max:smallint; res:simple;
  24. begin
  25. for i:=0 to n-1 do res[i]:=0;
  26. for i:=0 to n-1 do begin
  27. max:=-1;
  28. for j:=0 to n-1 do
  29. if (data[j]>=max) and (isSame(res, j+1)=False) then begin
  30. index:=j; max:=data[j]; end;
  31. res[i]:=index+1;
  32. end;
  33. converter:=res;
  34. end;
  35.  
  36. begin
  37. read(n);
  38. for i:=0 to n-1 do read(data[i]);
  39.  
  40. writeArr(converter(data));
  41. end.
Success #stdin #stdout 0s 5284KB
stdin
5
65 87 23 67 0
stdout
2 4 1 3 5