-
Notifications
You must be signed in to change notification settings - Fork 0
/
day2.cpp
45 lines (38 loc) · 839 Bytes
/
day2.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
#include <iostream>
#include <string>
#include "data.h"
std::map<char, std::string> getReplacements()
{
std::map<char, std::string> ret{{':', " "}, {'-', " "}};
return ret;
}
void process(Data& data)
{
int good1 = 0;
int good2 = 0;
for(auto l: data.lines)
{
std::string& pass = l.words[3];
std::string& c = l.words[2];
long x = l.numbers[0];
long y = l.numbers[1];
int count = 0;
for(auto it:pass)
{
if (it == c[0])
{
count++;
}
}
if (count >= x && count <= y)
{
good1++;
}
if ((pass[x - 1] == c[0]) ^ (pass[y - 1] == c[0]))
{
good2++;
}
}
std::cout << good1 << std::endl;
std::cout << good2 << std::endl;
}