aoc_omni/cpp/2015/1/problem.cpp
2023-12-19 14:32:26 -05:00

32 lines
588 B
C++

#include <iostream>
#include <fstream>
#include <string>
int main() {
std::ifstream input_file ("../data/2015/1/input.txt");
int floor = 0;
while(input_file) {
char c = input_file.get();
if (c == '(') floor++;
else if (c == ')') floor--;
}
std::cout << "Part 1: " << floor << "\n";
input_file.clear();
input_file.seekg(0);
floor = 0;
int steps = 0;
while(input_file) {
char c = input_file.get();
if (c == '(') floor++;
else if (c == ')') floor--;
steps++;
if (floor < 0) break;
}
std::cout << "Part 2: " << steps << "\n";
}