-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaoc2203.cc
82 lines (70 loc) · 1.15 KB
/
aoc2203.cc
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
#include "iostream"
#include "vector"
#include "string"
using namespace std;
int calc(char c);
int main()
{
vector<string> v;
string ss;
int x;
int r = 0;
int r2 = 0;
while (cin >> ss)
v.push_back(ss);
x = -1;
while (++x < (int) v.size())
{
string s = v[x];
int len = (int) s.length();
int c;
int i, j;
bool ok = false, ok2 = false;
i = -1;
while (++i < len / 2 && !ok)
{
c = s[i];
j = len / 2 - 1;
while (++j < len && !ok)
{
if (c == s[j])
{
r += calc(c);
ok = true;
}
}
}
// part 2
if (x > (int) v.size() - 3 || x % 3)
continue ;
string n = v[x + 1]; // next
string nn = v[x + 2]; // next next
i = -1;
ok = false;
ok2 = false;
while (++i < len && !(ok && ok2))
{
int it;
ok = false;
ok2 = false;
c = s[i];
it = n.find((char) c);
if (it ^ string::npos)
ok = true;
it = nn.find((char) c);
if (it ^ string::npos)
ok2 = true;
if (ok && ok2)
r2 += calc(c);
}
}
cout << "Star 1: " << r << endl;
cout << "Star 2: " << r2 << endl;
}
int calc(char c)
{
if (c <= 'z' && c >= 'a')
return c - 'a' + 1;
else
return c - 'A' + 27;
}