-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathday_05a.cpp
50 lines (46 loc) · 1.26 KB
/
day_05a.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
#include <fstream>
#include <iostream>
#include <string>
#include <vector>
bool is_vowel (const char c) {
return c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u';
}
bool is_forbidden(const char c1, const char c2) {
if (c1 == 'a' && c2 == 'b') return true;
if (c1 == 'c' && c2 == 'd') return true;
if (c1 == 'p' && c2 == 'q') return true;
if (c1 == 'x' && c2 == 'y') return true;
return false;
}
int main(int argc, char* argv[]) {
std::string input = "../input/day_05_input";
if (argc > 1) {
input = argv[1];
}
std::ifstream file(input);
std::string line;
int nice_count = 0;
while(std::getline(file, line)) {
int vowel_count = 0;
bool contains_repeated = false;
bool contains_forbidden = false;
for (int i = 0; i < line.size() - 1; i++) {
if (is_vowel(line[i])) {
vowel_count++;
}
if (line[i] == line[i+1]) {
contains_repeated = true;
}
if (is_forbidden(line[i], line[i+1])) {
contains_forbidden = true;
break;
}
}
if (is_vowel(line[line.size() - 1])) vowel_count++;
if (vowel_count>=3 &&contains_repeated && !contains_forbidden) {
nice_count++;
}
}
std::cout << nice_count << '\n';
return 0;
}