-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy path145.cpp
80 lines (78 loc) · 1.44 KB
/
145.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
80
#include <iostream>
#include <algorithm>
#include <sstream>
#include <cstdio>
using namespace std;
int main(int argc, char *argv[]) {
string s;
getline(cin, s);
int N = atoi(s.c_str());
getline(cin, s);
int cnt[256] = {};
for (char c : s) {
cnt[c] += 1;
}
int ans = cnt['z'];
cnt['z'] = 0;
while (cnt['y'] && cnt['u'] && cnt['k'] && cnt['i']) {
int i;
for (i = 'a'; i < 'i'; ++i) {
if (cnt[i]) {
break;
}
}
if (i >= 'i') {
break;
}
++ans;
cnt['y'] -= 1, cnt['u'] -= 1, cnt['k'] -= 1, cnt['i'] -= 1, cnt[i] -= 1;
}
while (cnt['y'] && cnt['u'] && cnt['k'] && cnt['i'] >= 2) {
++ans;
cnt['y'] -= 1, cnt['u'] -= 1, cnt['k'] -= 1, cnt['i'] -= 2;
}
while (cnt['y'] && cnt['u'] && cnt['k'] && cnt['j']) {
++ans;
cnt['y'] -= 1, cnt['u'] -= 1, cnt['k'] -= 1, cnt['j'] -= 1;
}
while (cnt['y'] && cnt['u'] && cnt['k'] >= 2) {
++ans;
cnt['y'] -= 1, cnt['u'] -= 1, cnt['k'] -= 2;
}
while (cnt['y'] && cnt['u']) {
int i;
for (i = 'l'; i < 'u'; ++i) {
if (cnt[i]) {
break;
}
}
if (i >= 'u') {
break;
}
++ans;
cnt['y'] -= 1, cnt['u'] -= 1, cnt[i] -= 1;
}
while (cnt['y'] && cnt['u'] >= 2) {
++ans;
cnt['y'] -= 1, cnt['u'] -= 2;
}
while (cnt['y']) {
int i;
for (i = 'v'; i < 'y'; ++i) {
if (cnt[i]) {
break;
}
}
if (i >= 'y') {
break;
}
++ans;
cnt['y'] -= 1, cnt[i] -= 1;
}
while (cnt['y'] >= 2) {
cnt['y'] -= 2;
++ans;
}
cout << ans << endl;
return 0;
}