-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaoc1904_different_pwds.cpp
95 lines (81 loc) · 2.53 KB
/
aoc1904_different_pwds.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
/* ************************************************************************** */
/* */
/* \\ /`/`` */
/* ~\o o_ 0 0\ */
/* / \__) (u ); _ _ */
/* / \/ \/ / \ \/ \/ \ */
/* /( . . ) ( )\ */
/* / \_____/ \_______/ \ */
/* [] [] [[] [[] *. */
/* []] []] [[] [[] */
/* */
/* ****************************************************************** nuo *** */
#include "iostream"
#include "sstream"
// DRIVE
int is_increased(std::string s);
int has_repeat(std::string s);
int has_pair(std::string s);
int main(int argc, char **argv)
{
int count_strict, count_lazy, a, b;
if (argc != 2) return (1);
std::stringstream ss(argv[1]);
ss >> a >> b;
b = 1 - b;
count_strict = 0;
count_lazy = 0;
while (a < b)
{
std::stringstream ss;
std::string s;
ss << a;
ss >> s;
if (has_repeat(s) && is_increased(s))
{
count_lazy++;
if (has_pair(s)) count_strict++;
}
a++;
}
std::cout << "Star 1 : " << count_lazy << std::endl;
std::cout << "Star 2 : " << count_strict << std::endl;
return (0);
}
//
int has_pair(std::string s)
{
int count, i, j;
i = 0;
while (s[i])
{
count = j = 0;
while (s[j])
{
if (s[i] == s[j++]) count++;
}
if (count == 2) return (1);
i++;
}
return (0);
}
int has_repeat(std::string s)
{
int i = 0;
while (s[i + 1])
{
if (s[i + 1] == s[i]) return (1);
i++;
}
return (0);
}
int is_increased(std::string s)
{
int i = 0;
while (s[i + 1])
{
if (s[i] > s[i + 1]) return (0);
i++;
}
return (1);
}