From 0aefd410a18acf826af5187cdb038fd9b4f25fc5 Mon Sep 17 00:00:00 2001 From: Sebastiano Tronto Date: Sun, 1 Dec 2024 09:40:19 +0100 Subject: Started 2024 + day 1 --- 2024/01/Makefile | 24 ++++++++++++++++++++++++ 2024/01/b.out | Bin 0 -> 78536 bytes 2024/01/day01a.cpp | 24 ++++++++++++++++++++++++ 2024/01/day01b.cpp | 21 +++++++++++++++++++++ 4 files changed, 69 insertions(+) create mode 100644 2024/01/Makefile create mode 100755 2024/01/b.out create mode 100644 2024/01/day01a.cpp create mode 100644 2024/01/day01b.cpp (limited to '2024/01') diff --git a/2024/01/Makefile b/2024/01/Makefile new file mode 100644 index 0000000..706085c --- /dev/null +++ b/2024/01/Makefile @@ -0,0 +1,24 @@ +CC=g++ -std=c++20 -g -Wall + +a: + ${CC} -o a.out day01a.cpp + +b: + ${CC} -o b.out day01b.cpp + +clean: + rm -f a b + +atest: a + ./a.out + +btest: b + ./b.out + +arun: a + ./a.out < input + +brun: b + ./b.out < input + +.PHONY: a b clean atest btest arun brun diff --git a/2024/01/b.out b/2024/01/b.out new file mode 100755 index 0000000..3b75578 Binary files /dev/null and b/2024/01/b.out differ diff --git a/2024/01/day01a.cpp b/2024/01/day01a.cpp new file mode 100644 index 0000000..e4a61e0 --- /dev/null +++ b/2024/01/day01a.cpp @@ -0,0 +1,24 @@ +#include +#include +#include +using namespace std; + +int main() { + int x, y, tot; + vector v, w; + + while (cin >> x >> y) { + v.push_back(x); + w.push_back(y); + } + + sort(v.begin(), v.end()); + sort(w.begin(), w.end()); + + tot = 0; + for (unsigned i = 0; i < v.size(); i++) + tot += abs(v[i] - w[i]); + + cout << tot << endl; + return 0; +} diff --git a/2024/01/day01b.cpp b/2024/01/day01b.cpp new file mode 100644 index 0000000..91ef0db --- /dev/null +++ b/2024/01/day01b.cpp @@ -0,0 +1,21 @@ +#include +#include +#include +using namespace std; + +int main() { + int x, y, tot; + vector v, w; + + while (cin >> x >> y) { + v.push_back(x); + w.push_back(y); + } + + tot = 0; + for (unsigned i = 0; i < v.size(); i++) + tot += v[i] * count(w.begin(), w.end(), v[i]); + + cout << tot << endl; + return 0; +} -- cgit v1.3