fork download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. void bubbleSort(int *a, int len)
  5. {
  6. for (int i = 0; i < len; ++i)
  7. for (int j = i + 1; j < len; ++j)
  8. if (a[i] < a[j]) {
  9. int t = a[i];
  10. a[i] = a[j];
  11. a[j] = t;
  12. }
  13. }
  14.  
  15. int func(int *a, int len, int n)
  16. {
  17.  
  18. int *b = malloc(sizeof(int) * len), r = 0, base = 1;
  19. --n;
  20. for (int i = 0; i < len; ++i)
  21. b[i] = a[i];
  22. bubbleSort(b, len);
  23. for (int i = 2; i <= len; ++i)
  24. base *= i;
  25. for (; len; --len) {
  26. base /= len;
  27. int nn = (n / base) + 1;
  28. int pos = 0;
  29. for (int i = 0; nn; ++i) {
  30. pos = i;
  31. if (b[i] >= 0)
  32. --nn;
  33. }
  34. r *= 10;
  35. r += b[pos];
  36. b[pos] = -1;
  37. n %= base;
  38. }
  39. return r;
  40. }
  41.  
  42. int main()
  43. {
  44. int a[] = {2, 3, 5, 7};
  45. int len = sizeof(a) / sizeof(a[0]);
  46. for (int i = 1; i <= 24; ++i)
  47. printf("%d\n", func(a, len, i));
  48. return 0;
  49. }
  50.  
Success #stdin #stdout 0s 2380KB
stdin
Standard input is empty
stdout
7532
7523
7352
7325
7253
7235
5732
5723
5372
5327
5273
5237
3752
3725
3572
3527
3275
3257
2753
2735
2573
2537
2375
2357