-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
solve(day 1): Historian hysteria part 1
- Loading branch information
0 parents
commit 06641dc
Showing
4 changed files
with
1,069 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
runfile |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
#include <bits/stdc++.h> | ||
|
||
using namespace std; | ||
|
||
typedef long long ll; | ||
typedef vector<ll> vecLL; | ||
|
||
int main() { | ||
ios::sync_with_stdio(0); | ||
cin.tie(0); | ||
|
||
ll l1 = 0; | ||
ll l2 = 0; | ||
|
||
vecLL list1 = {}; | ||
vecLL list2 = {}; | ||
|
||
// Read input file | ||
ifstream inputFile("./01/input.txt"); | ||
|
||
if (!inputFile.is_open()) { | ||
cerr << "Error: Could not open file.\n"; | ||
return 1; | ||
} | ||
|
||
// Build both lists from input | ||
while (inputFile >> l1 >> l2) { | ||
cout << "l1: " << l1 << " l2: " << l2 << '\n'; | ||
list1.push_back(l1); | ||
list2.push_back(l2); | ||
} | ||
|
||
// Close file (free memory) | ||
inputFile.close(); | ||
|
||
// Sort both lists | ||
sort(list1.begin(), list1.end()); | ||
sort(list2.begin(), list2.end()); | ||
|
||
// Compare each element and sum absolute diff (both lists are same size) | ||
ll diff = 0; | ||
|
||
for (size_t i = 0; i < list1.size(); i++) { | ||
diff += abs(list1[i] - list2[i]); | ||
} | ||
|
||
cout << "diff: " << diff << '\n'; | ||
|
||
return 0; | ||
} |
Oops, something went wrong.