completed day 1
This commit is contained in:
parent
1f7d96ad3f
commit
31b1c51bf5
3 changed files with 47 additions and 0 deletions
43
1/puzzle1p2.cpp
Normal file
43
1/puzzle1p2.cpp
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
#include <stdio.h>
|
||||
#include <list>
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <unordered_map>
|
||||
|
||||
using namespace std;
|
||||
|
||||
list<int> listOne{};
|
||||
list<int> listTwo{};
|
||||
|
||||
unordered_map<int, int> listTwoMap;
|
||||
|
||||
int simscore = 0;
|
||||
|
||||
int main(){
|
||||
|
||||
ifstream puzzle("input.txt");
|
||||
|
||||
int tempOne, tempTwo;
|
||||
|
||||
while (puzzle >> tempOne >> tempTwo)
|
||||
{
|
||||
listOne.push_back(tempOne);
|
||||
listTwo.push_back(tempTwo);
|
||||
}
|
||||
|
||||
puzzle.close();
|
||||
|
||||
for (int num:listTwo){
|
||||
listTwoMap[num]++;
|
||||
}
|
||||
|
||||
for (int listOneItem = 0; !listOne.empty(); listOneItem= listOne.front()) {
|
||||
if(listTwoMap.contains(listOneItem)){
|
||||
simscore += listOneItem * listTwoMap[listOneItem];
|
||||
}
|
||||
|
||||
listOne.pop_front();
|
||||
}
|
||||
|
||||
printf("total simularity: %i\n", simscore);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue