-
Notifications
You must be signed in to change notification settings - Fork 0
/
box.cpp
124 lines (108 loc) · 3.09 KB
/
box.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
/* ******************************************** */
/* */
/* \\ /`/`` */
/* ~\o o_ 0 0\ */
/* / \__) (u ); _ _ */
/* / \/ \/ / \ \/ \/ \ */
/* /( . . ) ( )\ */
/* / \_____/ \_______/ \ */
/* [] [] [[] [[] *. */
/* []] []] [[] [[] */
/* */
/* ************************************ nuo *** */
#include <iostream>
#include <vector>
int seen(char c, std::vector< char > arr);
int post(std::string s1, std::string s2);
// DRIVE
int main (void)
{
std::vector< std::string > id;
std::string s;
int count, i, j;
int doubler = 0;
int tripler = 0;
int checksum;
int p;
// Part 1
while (std::cin >> s)
{
std::vector< char > temp;
int doubler_checked = 0;
int tripler_checked = 0;
id.push_back(s);
i = 0;
while (s[i])
{
count = 1;
if (!seen(s[i], temp))
{
temp.push_back(s[i]);
j = i + 1;
while (s[j])
{
if (s[j++] == s[i]) count++;
}
}
if (count == 2 && !doubler_checked)
{
doubler_checked++;
doubler++;
}
if (count == 3 && !tripler_checked)
{
tripler_checked++;
tripler++;
}
i++;
}
}
checksum = doubler * tripler;
// Part 2
p = -1;
i = 0;
while (i < (int) id.size())
{
j = i + 1;
while (j < (int) id.size() && p < 0)
{
p = post(id[i], id[j]);
j++;
}
if (p != -1) break;
i++;
}
std::cout << "Star 1 : " << checksum << std::endl;
std::cout << "star 2 : ";
j = 0;
while (id[i][j])
{
if (j != p)
std::cout << id[i][j];
j++;
}
std::cout << std::endl;
}
//
int post(std::string s1, std::string s2)
{
int count, post, i;
count = i = 0;
while (s1[i] && s2[i])
{
if (s1[i] - s2[i])
{
post = i;
count++;
}
i++;
}
if (count == 1) return (post);
return (-1);
}
int seen(char c, std::vector< char > arr)
{
if (std::find(arr.begin(), arr.end(), c) == arr.end())
return (0);
return (1);
}