-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcons.cpp
79 lines (64 loc) · 1.51 KB
/
cons.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pi = pair<ll, ll>;
using vi = vector<ll>;
vector<char> vowels = {'A', 'E', 'I', 'O', 'U'};
bool isVowel(char c) {
return find(vowels.begin(), vowels.end(), c) != vowels.end();
}
void solve() {
string s;
cin >> s;
char max_v;
int max_v_cnt = 0;
char max_c;
int max_c_cnt = 0;
int max_char[26];
memset(max_char, 0, sizeof(max_char));
for (char c : s) {
max_char[c - 'A']++;
}
for (int i = 0; i < 26; i++) {
// if vowel
if (isVowel((char)(i + 'A'))) {
if(max_char[i] > max_v_cnt) {
max_v_cnt = max_char[i];
max_v = (char)(i + 'A');
}
} else {
if (max_char[i] > max_c_cnt) {
max_c_cnt = max_char[i];
max_c = (char)(i + 'A');
}
}
}
// sw to vowel
int best_vowel = 0;
for (char c : s) {
if(isVowel(c)) {
best_vowel += c == max_v ? 0 : 2;
} else
best_vowel++;
}
// sw to cons
int best_cons = 0;
for (char c : s) {
if (!isVowel(c)) {
best_cons += c == max_c ? 0 : 2;
} else
best_cons++;
}
cout << min(best_vowel, best_cons) << endl;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t;
cin >> t;
for (int i = 1; i <= t; i++) {
cout << "Case #" << i << ": ";
solve();
}
return 0;
}