blob: 7678742a7752cfcfed8655912f0a1efb2ff4c1cf (
plain)
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
|
#include "common.h"
#include <vector>
#include <map>
namespace aoc2022 {
struct valve {
line_view name;
int rate = 0;
std::vector<line_view> others;
friend bool operator<(const valve& v1, const valve& v2) {
return v1.rate > v2.rate;
}
void get_number(const char** pp, int* d) {
const char* p = *pp;
while(*p >= '0' && *p <= '9') {
*d = *d * 10 + *p - '0';
p++;
}
*pp = p;
}
bool isAZ(const char* p) {
return *p >= 'A' && *p <= 'Z';
}
bool is09(const char* p) {
return *p >= '0' && *p <= '9';
}
valve(line_view lv) {
const char *p = lv.line;
while (p < lv.line + lv.length) {
if (is09(p)) {
get_number(&p, &rate);
}
if (isAZ(p) && isAZ(p+1)) {
if (*(p+3) == 'h') {
name = line_view{p, 2};
}
else {
others.push_back({p, 2});
}
}
p++;
}
}
};
std::pair<int, int> day16(line_view);
}
|