This repository has been archived on 2021-06-30. You can view files and clone it, but cannot push or open issues or pull requests.
aoc2020/day_1/main.cpp

60 lines
1.1 KiB
C++

#include <iostream>
#include <fstream>
#include <vector>
int part_1();
int part_2();
int main() {
part_1();
part_2();
}
int part_1() {
std::vector<int> vector;
std::ifstream input("../input.txt");
std::string line;
while(std::getline(input, line)) {
int num = std::stoi(line);
vector.push_back(num);
}
for (int i : vector) {
for (int j : vector) {
if (i + j == 2020) {
std::cout << (i * j) << std::endl;
return 0;
}
}
}
return 1;
}
int part_2() {
std::vector<int> vector;
std::ifstream input("../input.txt");
std::string line;
while(std::getline(input, line)) {
int num = std::stoi(line);
vector.push_back(num);
}
for (int i : vector) {
for (int j : vector) {
for (int k : vector) {
if (i + j + k == 2020) {
std::cout << (i * j * k) << std::endl;
return 0;
}
}
}
}
return 1;
}