From 1997482305dab1a3804f084048ff48797339908a Mon Sep 17 00:00:00 2001 From: dzwdz Date: Thu, 1 Dec 2022 20:00:08 +0100 Subject: day 1 part 1 --- 22.1/main.cpp | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 22.1/main.cpp (limited to '22.1') diff --git a/22.1/main.cpp b/22.1/main.cpp new file mode 100644 index 0000000..4a33aca --- /dev/null +++ b/22.1/main.cpp @@ -0,0 +1,35 @@ +#include +#include +#include +using namespace std; + +class Solution { + long best = -1; + long curtotal = 0; +public: + + void addItem(long cals) { + curtotal += cals; + } + void endElf() { + best = max(best, curtotal); + curtotal = 0; + } + long getAnswer() { return best; } +}; + + +int +main() +{ + Solution sol; + for (string line; getline(cin, line); ) { + if (line.length() > 0) { + sol.addItem(stol(line)); + } else { + sol.endElf(); + } + } + sol.endElf(); + cout << sol.getAnswer() << endl; +} -- cgit 1.4.1-2-gfad0