-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDsort
More file actions
64 lines (54 loc) · 829 Bytes
/
Copy pathDsort
File metadata and controls
64 lines (54 loc) · 829 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
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int key(int a, char *s)
{
return (int) s[a];
}
void distribution(int(*key)(int a, char *s), int m, char *s, int n)
{
int count[m];
int i, k, j = 0;
int last = 0;
for (i = 0; i < m; i++)
{
count[i] = 0;
}
while (j < n)
{
k = key(j, s);
if (k >= 0) count[k]++;
j++;
}
i = 1;
while (i < m)
{
count[i] += count[i - 1];
i++;
}
j = n - 1;
char *d = (char*) malloc(1000001* sizeof(char));
while (j >= 0)
{
k = key(j, s);
if (k >= 0)
{
i = count[k] - 1;
count[k] = i;
d[i] = s[j];
}
j--;
}
for (i = 0; i < n; i++) s[i] = d[i];
free(d);
}
int main()
{
int i;
char *s = (char*) malloc(1000001* sizeof(char));
fgets(s, 1000001, stdin);
distribution(key, 125, s, strlen(s));
printf("%s", s);
free(s);
return 0;
}