-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathE.cpp
47 lines (46 loc) · 1008 Bytes
/
E.cpp
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
#include <fstream>
#include <string>
#include <vector>
std::vector <std::string> csort(std::vector <std::string>&a, int p)
{
std::vector <int> counts(256);
std::vector <std::string> ans(a.size());
for (int i = 0; i<a.size(); i++)
{
counts[(int)a[i][p]]++;
}
for (int i = 1; i < counts.size(); i++)
{
counts[i] += counts[i-1];
}
for (int i=a.size()-1; i >=0; i--)
{
int numb = counts[(int)a[i][p]];
ans[numb-1] = a[i];
counts[(int)a[i][p]]--;
}
return ans;
}
int main()
{
std::ifstream fin("radixsort.in");
std::ofstream fout("radixsort.out");
int n,k,m;
fin >> n >> m >> k;
std::vector <std::string> a(n);
for(int i = 0; i < n; i++)
{
fin >> a[i];
}
for(int i = 0; i < k; i++)
{
a = csort(a,m-1-i);
}
for(int i = 0; i<n; i++)
{
fout << a[i] << "\n";
}
fin.close();
fout.close();
return 0;
}