-
Notifications
You must be signed in to change notification settings - Fork 0
/
countRainbow.cpp
40 lines (35 loc) · 1 KB
/
countRainbow.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
#include <iostream>
#include <map>
#include <string>
#include <algorithm>
using namespace std;
string base[] = {"red", "violet", "orange", "yellow", "green", "indigo", "blue"};
int countRainbow(string str)
{
map<char, int> counter;
for (char x : str) counter[x]++;
int result = 0;
while(true) {
bool makeRB = true;
for (string x : base) {
bool makeCL = true;
for (char ch : x) if (counter[ch] <= 0) {
makeCL = false;
break;
}
if (!makeCL) {
makeRB = false;
break;
} else {
for (char ch : x) counter[ch]--;
}
}
if (makeRB) result++;
else break;
}
return result;
}
int main() {
cout << countRainbow("ngegooglnonnaugrnyeniroowealrlrerndrgyneeouerndeitnneboeuigwoielngiblboreoeogrlaolordwielvleeeiaylaelueweoelaloubgerllvegdulwonoaebigdorggwlnlgeriyldleeoenybbrelreuydengeegotiaao");
return 0;
}