Advertisement
Guest User

Untitled

a guest
Mar 22nd, 2018
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.83 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. struct Date {
  4. int Day, Month, Year;
  5. };
  6.  
  7. int main() {
  8. int n;
  9. scanf("%d", &n);
  10. int b[10][n],k = 10,m = 1,h = 0,c;
  11. for (int j = 0;j < 10;j++)
  12. for(int i = 0;i < n;i++)
  13. b[j][i] = -1;
  14. struct Date a[n],d[n];
  15. for (int i = 0; i < n;i++){
  16. scanf("%d", &a[i].Year);
  17. scanf("%d", &a[i].Month);
  18. scanf("%d", &a[i].Day);
  19. }
  20. for (int j = 0; j < 2;j++) {
  21. int x = 0;
  22. for (int i = 0; i < n; i++) {
  23. h = 0;
  24. c = a[i].Day;
  25. while ((b[(c%k)/m][h] != -1) && (h < n))
  26. h++;
  27. if (h < n)
  28. b[(c%k)/m][h] = i;
  29. }
  30. for (int i = 0;i < 10;i++) {
  31. h = 0;
  32. while ((h < n) && (x < n)){
  33. if (b[i][h] != -1) {
  34. d[x] = a[b[i][h]];
  35. x++;
  36. }
  37. h++;
  38. }
  39. }
  40. for (int i = 0;i < n;i++)
  41. a[i] = d[i];
  42. for (int f = 0;f < 10;f++)
  43. for(int i = 0;i < n;i++)
  44. b[f][i] = -1;
  45. k *= 10;
  46. m *= 10;
  47. }
  48. k = 10;
  49. m = 1;
  50. for (int j = 0; j < 2;j++) {
  51. int x = 0;
  52. for (int i = 0; i < n; i++) {
  53. h = 0;
  54. c = a[i].Month;
  55. while ((b[(c%k)/m][h] != -1) && (h < n))
  56. h++;
  57. if (h < n)
  58. b[(c%k)/m][h] = i;
  59. }
  60. for (int i = 0;i < 10;i++) {
  61. h = 0;
  62. while ((h < n) && (x < n)){
  63. if (b[i][h] != -1) {
  64. d[x] = a[b[i][h]];
  65. x++;
  66. }
  67. h++;
  68. }
  69. }
  70. for (int i = 0;i < n;i++)
  71. a[i] = d[i];
  72. for (int f = 0;f < 10;f++)
  73. for(int i = 0;i < n;i++)
  74. b[f][i] = -1;
  75. k *= 10;
  76. m *= 10;
  77. }
  78. k = 10;
  79. m = 1;
  80. for (int j = 0; j < 4;j++) {
  81. int x = 0;
  82. for (int i = 0; i < n; i++) {
  83. h = 0;
  84. c = a[i].Year;
  85. while ((b[(c%k)/m][h] != -1) && (h < n))
  86. h++;
  87. if (h < n)
  88. b[(c%k)/m][h] = i;
  89. }
  90. for (int i = 0;i < 10;i++) {
  91. h = 0;
  92. while ((h < n) && (x < n)){
  93. if (b[i][h] != -1) {
  94. d[x] = a[b[i][h]];
  95. x++;
  96. }
  97. h++;
  98. }
  99. }
  100. for (int i = 0;i < n;i++)
  101. a[i] = d[i];
  102. for (int f = 0;f < 10;f++)
  103. for(int i = 0;i < n;i++)
  104. b[f][i] = -1;
  105. k *= 10;
  106. m *= 10;
  107. }
  108. for (int i = 0l;i < n;i++)
  109. printf("%d %d %d ", a[i].Year, a[i].Month, a[i].Day);
  110.  
  111. return 0;
  112. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement