summaryrefslogtreecommitdiff
path: root/2022/Cpp/Day1/main.cpp
diff options
context:
space:
mode:
authoromagdy7 <omar.professional8777@gmail.com>2022-12-04 17:36:44 +0200
committeromagdy7 <omar.professional8777@gmail.com>2022-12-04 17:36:44 +0200
commit616af4d6944d9c6436e36ab1ef38238819ccea64 (patch)
tree25247c469f2a5b7ebab584c47def25fa2cd07814 /2022/Cpp/Day1/main.cpp
parentb6581928ca05708bc8aa1cc1c2b6ab44e7100a1a (diff)
downloadaoc-616af4d6944d9c6436e36ab1ef38238819ccea64.tar.xz
aoc-616af4d6944d9c6436e36ab1ef38238819ccea64.zip
Added Rust solution for day3 and day4
Diffstat (limited to '2022/Cpp/Day1/main.cpp')
-rw-r--r--2022/Cpp/Day1/main.cpp35
1 files changed, 35 insertions, 0 deletions
diff --git a/2022/Cpp/Day1/main.cpp b/2022/Cpp/Day1/main.cpp
new file mode 100644
index 0000000..6f9f848
--- /dev/null
+++ b/2022/Cpp/Day1/main.cpp
@@ -0,0 +1,35 @@
+#include<bits/stdc++.h>
+using namespace std;
+
+using ll = long long;
+using vll = vector<long long>;
+
+#define pb push_back
+#define all(x) (x).begin(), (x).end()
+#define rall(x) (x).rbegin(), (x).rend()
+
+void solve() {
+ string s;
+ ll sum = 0;
+ ll mx = 0;
+ vll v;
+ while(getline(cin, s)) {
+ if (s.empty()) {
+ v.pb(sum);
+ sum = 0;
+ } else {
+ int x = stoi(s);
+ sum += x;
+ }
+ }
+ sort(rall(v));
+ cout << v[0] + v[1] + v[2] << '\n';
+}
+
+int main () {
+ ios_base::sync_with_stdio(false);
+ cin.tie(NULL);
+ solve();
+}
+
+