-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDateSort
More file actions
73 lines (63 loc) · 1010 Bytes
/
DateSort
File metadata and controls
73 lines (63 loc) · 1010 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#include <stdio.h>
struct Date
{
int Day, Month, Year;
};
int key(int m, struct Date d)
{
if (m == 32) return d.Day;
if (m == 13) return d.Month;
return d.Year - 1970;
}
void distribution(int m, struct Date *s, int n)
{
int count[m];
int i, k, j = 0;
for (i = 0; i < m; i++)
{
count[i] = 0;
}
while (j < n)
{
k = key(m, s[j]);
count[k]++;
j++;
}
i = 1;
while (i < m)
{
count[i] += count[i - 1];
i++;
}
j = n - 1;
struct Date d[n];
while (j >= 0)
{
k = key(m, s[j]);
i = count[k] - 1;
count[k] = i;
d[i] = s[j];
j--;
}
for (int i = 0; i < n; i++) s[i] = d[i];
}
void radix(struct Date *s, int n)
{
int i = 2;
int help[3] = { 61, 13, 32 };
while (i >= 0)
{
distribution(help[i], s, n);
i--;
}
}
int main()
{
int n, i;
scanf("%d", &n);
struct Date d[n];
for (i = 0; i < n; i++) scanf("%d %d %d", &d[i].Year, &d[i].Month, &d[i].Day);
radix(d, n);
for (i = 0; i < n; i++) printf("%04d %02d %02d\n", d[i].Year, d[i].Month, d[i].Day);
return 0;
}