completed day 1
This commit is contained in:
parent
1f7d96ad3f
commit
31b1c51bf5
3 changed files with 47 additions and 0 deletions
4
.vscode/tasks.json
vendored
4
.vscode/tasks.json
vendored
|
|
@ -5,6 +5,8 @@
|
||||||
"label": "C/C++: gcc build active file",
|
"label": "C/C++: gcc build active file",
|
||||||
"command": "/usr/bin/g++",
|
"command": "/usr/bin/g++",
|
||||||
"args": [
|
"args": [
|
||||||
|
"--std",
|
||||||
|
"gnu++23",
|
||||||
"-fdiagnostics-color=always",
|
"-fdiagnostics-color=always",
|
||||||
"-g",
|
"-g",
|
||||||
"${file}",
|
"${file}",
|
||||||
|
|
@ -28,6 +30,8 @@
|
||||||
"label": "C/C++: g++ build active file",
|
"label": "C/C++: g++ build active file",
|
||||||
"command": "/usr/bin/g++",
|
"command": "/usr/bin/g++",
|
||||||
"args": [
|
"args": [
|
||||||
|
"--std",
|
||||||
|
"gnu++23",
|
||||||
"-fdiagnostics-color=always",
|
"-fdiagnostics-color=always",
|
||||||
"-g",
|
"-g",
|
||||||
"${file}",
|
"${file}",
|
||||||
|
|
|
||||||
BIN
1/puzzle1p2
Executable file
BIN
1/puzzle1p2
Executable file
Binary file not shown.
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