did it in c++
This commit is contained in:
parent
38ec2988c9
commit
885e836f74
7 changed files with 1086 additions and 2 deletions
29
.vscode/launch.json
vendored
29
.vscode/launch.json
vendored
|
|
@ -7,6 +7,33 @@
|
|||
"cmakeDebugType": "external",
|
||||
"pipeName": "/tmp/vcpkg_ext_portfile_dbg",
|
||||
"preLaunchTask": "Debug vcpkg commands"
|
||||
},
|
||||
{
|
||||
"name": "C/C++: g++ build and debug active file",
|
||||
"type": "cppdbg",
|
||||
"request": "launch",
|
||||
"program": "${fileDirname}/${fileBasenameNoExtension}",
|
||||
"args": [],
|
||||
"stopAtEntry": false,
|
||||
"cwd": "${fileDirname}",
|
||||
"environment": [],
|
||||
"externalConsole": false,
|
||||
"MIMode": "gdb",
|
||||
"setupCommands": [
|
||||
{
|
||||
"description": "Enable pretty-printing for gdb",
|
||||
"text": "-enable-pretty-printing",
|
||||
"ignoreFailures": true
|
||||
},
|
||||
{
|
||||
"description": "Set Disassembly Flavor to Intel",
|
||||
"text": "-gdb-set disassembly-flavor intel",
|
||||
"ignoreFailures": true
|
||||
}
|
||||
],
|
||||
"preLaunchTask": "C/C++: g++ build active file",
|
||||
"miDebuggerPath": "/usr/bin/gdb"
|
||||
}
|
||||
]
|
||||
],
|
||||
"version": "2.0.0"
|
||||
}
|
||||
22
.vscode/tasks.json
vendored
22
.vscode/tasks.json
vendored
|
|
@ -3,7 +3,7 @@
|
|||
{
|
||||
"type": "cppbuild",
|
||||
"label": "C/C++: gcc build active file",
|
||||
"command": "/usr/bin/gcc",
|
||||
"command": "/usr/bin/g++",
|
||||
"args": [
|
||||
"-fdiagnostics-color=always",
|
||||
"-g",
|
||||
|
|
@ -22,6 +22,26 @@
|
|||
"isDefault": true
|
||||
},
|
||||
"detail": "Task generated by Debugger."
|
||||
},
|
||||
{
|
||||
"type": "cppbuild",
|
||||
"label": "C/C++: g++ build active file",
|
||||
"command": "/usr/bin/g++",
|
||||
"args": [
|
||||
"-fdiagnostics-color=always",
|
||||
"-g",
|
||||
"${file}",
|
||||
"-o",
|
||||
"${fileDirname}/${fileBasenameNoExtension}"
|
||||
],
|
||||
"options": {
|
||||
"cwd": "${fileDirname}"
|
||||
},
|
||||
"problemMatcher": [
|
||||
"$gcc"
|
||||
],
|
||||
"group": "build",
|
||||
"detail": "Task generated by Debugger."
|
||||
}
|
||||
],
|
||||
"version": "2.0.0"
|
||||
|
|
|
|||
1000
1/input.txt
Normal file
1000
1/input.txt
Normal file
File diff suppressed because it is too large
Load diff
BIN
1/puzzle1
Executable file
BIN
1/puzzle1
Executable file
Binary file not shown.
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);
|
||||
}
|
||||
BIN
puzzle1
BIN
puzzle1
Binary file not shown.
Loading…
Add table
Add a link
Reference in a new issue