32 lines
588 B
C++
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";
|
|
}
|