Actualize un poco las soluciones en c++ por aprender cositas
This commit is contained in:
34
2020/day_1/report_repair.cc
Normal file
34
2020/day_1/report_repair.cc
Normal file
@@ -0,0 +1,34 @@
|
||||
#include <algorithm>
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <set>
|
||||
#include <string>
|
||||
|
||||
std::set<int> read_input_file() {
|
||||
std::ifstream file("input");
|
||||
std::set<int> data;
|
||||
std::string line;
|
||||
|
||||
while(std::getline(file, line))
|
||||
data.insert(std::stoi(line));
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
int main(){
|
||||
auto data = read_input_file();
|
||||
int iterations = 0;
|
||||
|
||||
for(auto &i: data) {
|
||||
int rest = 2020 - i;
|
||||
for(auto &j: data) {
|
||||
int second_rest = rest - j;
|
||||
if (data.count(second_rest)) {
|
||||
std::cout << i * j * second_rest << std::endl;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
Reference in New Issue
Block a user