-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathP10785.cpp
57 lines (55 loc) · 1.16 KB
/
P10785.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
48
49
50
51
52
53
54
55
56
57
#include <iostream>
#include <stdio.h>
/*
Minimize values.
Vovel,consonant,vovel,consonant,...
Consonant repeat max: 5
Vowel repeat max: 21
*/
int main() {
int N, n;
char vowels[5] = {'A','U','E','O','I'};
char consonants[21] = {'J','S',
'B','K','T',
'C','L',
'D','M','V',
'N','W',
'F','X',
'G','P','Y',
'H','Q','Z',
'R'};
int vCounts[26], cCounts[26];
for(int i = 0; i < 26; ++i)
vCounts[i] = cCounts[i] = 0;
std::cin >> N; // Cases.
for(int cas = 1; cas <= N; ++cas) {
std::cin >> n; // Name length.
for(int i = 0; i < n; ++i) {
if(i % 2 == 1) { // Consonant:
++cCounts[consonants[(i / 2) / 5]-'A'];
}
else { // Vowels:
++vCounts[vowels[(i / 2) / 21]-'A'];
}
}
std::cout << "Case " << cas << ": ";
int vI = 0;
int cI = 0;
for(int i = 0; i < n; ++i) {
if(i % 2 == 1) { // Consonant:
while(cCounts[cI] == 0)
++cI;
--cCounts[cI];
std::cout << (char)('A'+cI);
}
else { // Vowels:
while(vCounts[vI] == 0)
++vI;
--vCounts[vI];
std::cout << (char)('A'+vI);
}
}
std::cout << std::endl;
}
return 0;
}