-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaoc1505_nice_string.cpp
132 lines (115 loc) Β· 2.97 KB
/
aoc1505_nice_string.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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
/* ************************************************************************** */
/* */
/* \\ /`/`` */
/* ~\o o_ 0 0\ */
/* / \__) (u ); _ _ */
/* / \/ \/ / \ \/ \/ \ */
/* /( . . ) ( )\ */
/* / \_____/ \_______/ \ */
/* [] [] [[] [[] *. */
/* []] []] [[] [[] */
/* */
/* ****************************************************************** nuo *** */
#include "iostream"
#include "vector"
int count_double(std::string s);
int count_vowel(std::string s);
int count_pair(std::string s);
int count_efe(std::string s);
int count_ab(std::string s);
int main()
{
std::string s;
int prop;
int good_1 = 0;
int good_2 = 0;
while (std::cin >> s)
{
prop = 3;
if (count_double(s) > 0) prop--;
if (count_vowel(s) > 2) prop--;
if (count_ab(s) == 0) prop--;
if (prop == 0) good_1++;
prop = 2;
if (count_pair(s) > 0) prop--;
if (count_efe(s) > 0) prop--;
if (prop == 0) good_2++;
}
std::cout
<< "Star 1 : " << good_1 << '\n'
<< "star 2 : " << good_2 << '\n';
}
//
int count_pair(std::string s)
{
int i = 0;
int j;
int count = 0;
while (s[i])
{
j = i + 2;
while (s[j + 1])
{
if (s[i] == s[j] && s[i + 1] == s[j + 1])
count++;
j++;
}
i++;
}
return count;
}
int count_efe(std::string s)
{
int i = 2;
int count = 0;
while (s[i])
{
if (s[i - 2] == s[i]) count++;
i++;
}
return (count);
}
int count_vowel(std::string s)
{
char vowels [] = {'a', 'e', 'i', 'o', 'u'};
int i = 0;
int j;
int count = 0;
while (s[i])
{
j = 0;
while (vowels[j])
{
if (vowels[j] == s[i]) count++;
j++;
}
i++;
}
return (count);
}
int count_double(std::string s)
{
int i = 1;
int count = 0;
while (s[i])
{
if (s[i - 1] == s[i]) count++;
i++;
}
return (count);
}
int count_ab(std::string s)
{
int i = 1;
int count = 0;
while (s[i])
{
if ((s[i] == 'b' && s[i - 1] == 'a') || \
(s[i] == 'd' && s[i - 1] == 'c') || \
(s[i] == 'q' && s[i - 1] == 'p') || \
(s[i] == 'y' && s[i - 1] == 'x'))
count++;
i++;
}
return (count);
}