50 lines
898 B
C++
50 lines
898 B
C++
#include <fstream>
|
|
#include <iostream>
|
|
#include <set>
|
|
#include <sstream>
|
|
#include <string>
|
|
#include <vector>
|
|
|
|
int main()
|
|
{
|
|
std::ifstream ifs("data_test.txt");
|
|
if(!ifs.is_open())
|
|
{
|
|
std::cerr << "Missing data.txt." << std::endl;
|
|
return -1;
|
|
}
|
|
|
|
unsigned long total = 0;
|
|
unsigned long total_pt2 = 0;
|
|
|
|
std::vector<std::vector<long>> cals;
|
|
|
|
for(std::string line; std::getline(ifs, line); )
|
|
{
|
|
if(line == "")
|
|
continue;
|
|
|
|
cals.push_back({});
|
|
std::istringstream input(line);
|
|
// for each value in the line:
|
|
std::vector<long> nums;
|
|
for(std::string value; std::getline(input, value, ' '); )
|
|
cals.back().push_back(std::atoi(value.c_str()));
|
|
}
|
|
|
|
for(auto cal : cals)
|
|
{
|
|
for(auto num : cal)
|
|
{
|
|
std::cout << num << " ";
|
|
}
|
|
std::cout << std::endl;
|
|
}
|
|
|
|
|
|
std::cout << " Total: " << total << std::endl;
|
|
std::cout << "PT2 Total: " << total_pt2 << std::endl;
|
|
|
|
return 0;
|
|
}
|