aboutsummaryrefslogtreecommitdiff
path: root/src/2018/day4/aoc.h
diff options
context:
space:
mode:
authorkaiwu <kaiwu2004@gmail.com>2022-04-08 19:57:13 +0800
committerkaiwu <kaiwu2004@gmail.com>2022-04-08 19:57:13 +0800
commit875915109841d2acb5b30bafcba1d0e342d88cdd (patch)
tree043a9d0c958e9766aa6b14b1f6961d63e92928d3 /src/2018/day4/aoc.h
parent5db7670bfa3a107718b05f4d652e0850347d16d8 (diff)
downloadadvent-of-code-875915109841d2acb5b30bafcba1d0e342d88cdd.tar.gz
advent-of-code-875915109841d2acb5b30bafcba1d0e342d88cdd.zip
2018 day4 part1 most off
Diffstat (limited to 'src/2018/day4/aoc.h')
-rw-r--r--src/2018/day4/aoc.h48
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[] = {&timestamp.month, &timestamp.day, &timestamp.hour, &timestamp.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