diff options
author | dzwdz | 2022-12-01 20:00:08 +0100 |
---|---|---|
committer | dzwdz | 2022-12-01 20:00:08 +0100 |
commit | 1997482305dab1a3804f084048ff48797339908a (patch) | |
tree | b2a94eeccf6e33050edceec9ade195dc55ac8556 |
day 1 part 1
-rw-r--r-- | .gitignore | 3 | ||||
-rw-r--r-- | 22.1/main.cpp | 35 |
2 files changed, 38 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..567ae2b --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +cookie +*.in +*/a.out 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 <algorithm> +#include <iostream> +#include <string> +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; +} |