fork(1) download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. const int mval = 500;
  5. const int nval = 20;
  6.  
  7. int r[1001];
  8. int rII[1001];
  9.  
  10. int coot[501];
  11. int cootII[501];
  12. int cootIII[501];
  13. int cootIV[501];
  14.  
  15. int x=0;
  16. int k=0;
  17. int j=0;
  18. int i=0;
  19.  
  20. int main(void){
  21.  
  22. for(i; i<nval; i++){
  23. r[i] = rand() % 501;
  24. coot[r[i]]++;
  25. printf("%i, ", r[i]);
  26. }
  27.  
  28. for(i=0;i<500;i++)
  29. if(coot[i]>0){
  30. cootII[i] = j;
  31. cootIII[j] = k;
  32. k += coot[i];
  33. j++;
  34. }
  35.  
  36.  
  37. printf("\n");
  38.  
  39. for(i=0; i<nval; i++){
  40. x = cootII[r[i]];
  41. rII[cootIII[x]+cootIV[x]] = i;
  42. cootIV[x]++;
  43. }
  44.  
  45. for(i=0; i<nval; i++)
  46. printf("%i, ", r[rII[i]]);
  47.  
  48. printf("\n\n index \n");
  49.  
  50. for(i=0; i<nval; i++)
  51. printf("%i, ", rII[i]);
  52.  
  53.  
  54. return 0;
  55.  
  56. }
Success #stdin #stdout 0s 1848KB
stdin
Standard input is empty
stdout
7, 406, 105, 487, 113, 52, 490, 57, 498, 388, 50, 439, 80, 421, 131, 253, 129, 309, 208, 28, 
7, 28, 50, 52, 57, 80, 105, 113, 129, 131, 208, 253, 309, 388, 406, 421, 439, 487, 490, 498, 

 index 
0, 19, 10, 5, 7, 12, 2, 4, 16, 14, 18, 15, 17, 9, 1, 13, 11, 3, 6, 8,