forked from derekhh/HackerRank
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcountingsort4.cpp
More file actions
57 lines (50 loc) · 810 Bytes
/
countingsort4.cpp
File metadata and controls
57 lines (50 loc) · 810 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
//countingsort4.cpp
//The Full Counting Sort
//Algorithms - Sorting
//Author: derekhh
#include<iostream>
#include<string>
#include<vector>
using namespace std;
struct Pair
{
Pair() {}
Pair(int _val, string _str) : val(_val), str(_str) {}
int val;
string str;
};
vector<Pair> v;
vector<Pair> s;
int cnt[100];
int main()
{
int n, val;
string str;
cin >> n;
for (int i = 0; i < n; i++)
{
cin >> val >> str;
Pair p(val, str);
v.push_back(p);
cnt[val]++;
}
int total = 0;
for (int i = 0; i < 100; i++)
{
int tmp = cnt[i];
cnt[i] = total;
total += tmp;
}
s.resize(n);
for (int i = 0; i < n; i++)
{
s[cnt[v[i].val]] = v[i];
if (i < n / 2)
s[cnt[v[i].val]].str = "-";
cnt[v[i].val]++;
}
for (int i = 0; i < n; i++)
cout << s[i].str << " ";
cout << endl;
return 0;
}