Files
aoc/aoc.cpp
2024-12-02 17:23:49 +01:00

49 lines
1.1 KiB
C++

#include <fstream>
#include <vector>
#include <algorithm>
#include <ranges>
#include <numeric>
#include <cmath>
#include <utility>
#include "fmt/format.h"
using levels_t = std::vector<std::uint32_t>;
using reports_t = std::vector<levels_t>;
auto main([[maybe_unused]]int argc, [[maybe_unused]]char const* argv[]) -> int {
constexpr auto filename = "./dat/24/ex/02.txt";
std::ifstream strm{filename, std::ios::in};
if (!strm.is_open()) {
fmt::print("Error opening file: {}\n", filename);
return 1;
}
reports_t reports{};
levels_t levels{};
std::string str{};
while (strm) {
auto const c = char(strm.peek());
if (std::isdigit(c)) {
str += char(strm.get());
continue;
}
if (c == ' ') {
if (!str.empty()) {
levels.emplace_back(std::stoi(str));
str.clear();
}
}
if (c == '\n') {
if (!str.empty()) {
reports.emplace_back(std::move(levels));
str.clear();
}
}
strm.get();
}
return 0;
}