diff options
Diffstat (limited to 'src/2018/day4/aoc.h')
-rw-r--r-- | src/2018/day4/aoc.h | 48 |
1 files changed, 47 insertions, 1 deletions
diff --git a/src/2018/day4/aoc.h b/src/2018/day4/aoc.h index 4bfdbf3..563f0c0 100644 --- a/src/2018/day4/aoc.h +++ b/src/2018/day4/aoc.h @@ -3,4 +3,50 @@ namespace aoc2018 { -} +struct guard { + int id = 0; + struct { + int month; + int day; + int hour; + int minute; + } timestamp = {0, 0, 0, 0}; + enum { + on, + off, + } status = off; + + int offtime[60] = {0}; + int ontime[60] = {0}; + + 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; + } + + guard(line_view lv) { + int* ds[] = {×tamp.month, ×tamp.day, ×tamp.hour, ×tamp.minute, &id}; + const char* p = lv.line + 6; + int i{0}; + while (p < lv.line + lv.length) { + if (*p >= '0' && *p <= '9') { + get_number(&p, ds[i++]); + if (i == 4 && *(p + 2) == 'w') { + status = on; + } + } + p++; + } + if (id > 0) { + status = on; + } + }; +}; + +int day4(line_view); + +} // namespace aoc2018 |