organised 2024 year and added day4 in rust solution
This commit is contained in:
30
2024/1/day1bothparts/part1.cpp
Normal file
30
2024/1/day1bothparts/part1.cpp
Normal file
@@ -0,0 +1,30 @@
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <vector>
|
||||
#include <algorithm>
|
||||
#include <cmath>
|
||||
|
||||
int main() {
|
||||
std::ifstream f("b");
|
||||
|
||||
std::vector<int> x;
|
||||
std::vector<int> y;
|
||||
int l, r;
|
||||
|
||||
while (f >> l >> r) {
|
||||
x.push_back(l);
|
||||
y.push_back(r);
|
||||
}
|
||||
|
||||
std::sort(x.begin(), x.end());
|
||||
std::sort(y.begin(), y.end());
|
||||
|
||||
long t = 0;
|
||||
for (size_t i = 0; i < 4000000; i++) {
|
||||
t += std::abs(x[i] - y[i]);
|
||||
}
|
||||
|
||||
std::cout << t;
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user