aoc

My solutions for the Advent of Code
git clone https://git.tronto.net/aoc
Download | Log | Files | Refs | README

day01a.cpp (364B)


      1 #include <iostream>
      2 #include <algorithm>
      3 #include <vector>
      4 using namespace std;
      5 
      6 int main() {
      7 	int x, y, tot;
      8 	vector<int> v, w;
      9 
     10 	while (cin >> x >> y) {
     11 		v.push_back(x);
     12 		w.push_back(y);
     13 	}
     14 
     15 	sort(v.begin(), v.end());
     16 	sort(w.begin(), w.end());
     17 
     18 	tot = 0;
     19 	for (unsigned i = 0; i < v.size(); i++)
     20 		tot += abs(v[i] - w[i]);
     21 
     22 	cout << tot << endl;
     23 	return 0;
     24 }