did it in c++
This commit is contained in:
parent
38ec2988c9
commit
885e836f74
7 changed files with 1086 additions and 2 deletions
37
1/puzzle1.cpp
Normal file
37
1/puzzle1.cpp
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
#include <stdio.h>
|
||||
#include <list>
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
|
||||
using namespace std;
|
||||
|
||||
list<int> listOne{};
|
||||
list<int> listTwo{};
|
||||
|
||||
int totalDistance = 0;
|
||||
|
||||
int main(){
|
||||
|
||||
ifstream puzzle("input.txt");
|
||||
|
||||
int tempOne, tempTwo;
|
||||
|
||||
while (puzzle >> tempOne >> tempTwo)
|
||||
{
|
||||
listOne.push_back(tempOne);
|
||||
listTwo.push_back(tempTwo);
|
||||
}
|
||||
|
||||
puzzle.close();
|
||||
|
||||
listOne.sort();
|
||||
listTwo.sort();
|
||||
|
||||
for (int x=0; !listOne.empty();x++){
|
||||
totalDistance += listOne.front() + listTwo.front();
|
||||
listOne.pop_front();
|
||||
listTwo.pop_front();
|
||||
}
|
||||
|
||||
printf("total distance: %i\n", totalDistance);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue