summaryrefslogtreecommitdiff
path: root/2024/1B.cpp
diff options
context:
space:
mode:
authorlittleblack111 <littleblack11111@gmail.com>2024-12-02 13:29:56 +0800
committerlittleblack111 <littleblack11111@gmail.com>2024-12-02 15:23:32 +0800
commit228ddc94ba315c817fe52df83a886c299a2eaaf6 (patch)
tree72ed481ed1740fad094dc756d2f2d4d5f57b3634 /2024/1B.cpp
parenta8543766c548831583fa21031f93992090a32a1c (diff)
organize
Diffstat (limited to '2024/1B.cpp')
-rw-r--r--2024/1B.cpp41
1 files changed, 41 insertions, 0 deletions
diff --git a/2024/1B.cpp b/2024/1B.cpp
new file mode 100644
index 0000000..f6dff14
--- /dev/null
+++ b/2024/1B.cpp
@@ -0,0 +1,41 @@
+#include <bits/stdc++.h>
+#include "readfile.hpp"
+
+
+int main(int argc, char const *argv[])
+{
+ int res = 0;
+ std::vector<std::string> file = readfile("2.in");
+ if (file.empty()) {
+ return 1;
+ }
+ std::vector<int> left, right;
+ for (const auto &line : file) {
+ int n1, n2;
+ // put to vector
+ std::istringstream iss(line);
+ if (!(iss >> n1 >> n2)) {
+ std::cerr << "Invalid input line: " << line << std::endl;
+ return 1;
+ }
+ left.push_back(n1);
+ right.push_back(n2);
+ }
+
+ // count
+ if (left.size() != right.size()) {
+ std::cerr << "size mismatch: " << left.size() << " vs " << right.size() << std::endl;
+ return 1;
+ }
+
+ std::map<int, int> rightCount;
+ for (const int &num : right) {
+ rightCount[num]++;
+ }
+
+ for (const int &num : left) {
+ res += num * rightCount[num];
+ }
+
+ std::cout << res << std::endl;
+} \ No newline at end of file