1
0
Fork 0
Advent2021/Day 1/Pujan/cpp/main.cpp

43 lines
782 B
C++
Raw Permalink Normal View History

2021-12-01 07:10:37 +00:00
#include <fstream>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <vector>
int main()
{
std::string filename("data.txt");
std::ifstream input{filename};
int prev = 0;
int current = 0;
int counter = 0;
if(!input.is_open())
{
std::cerr << "Couldn't read file: " << filename << "\n";
return 1;
}
for (std::string line; std::getline(input, line);)
{
if (prev == 0)
{
prev = std::stoi(line);
continue;
}
else
{
current = std::stoi(line);
if (prev < current)
{
counter ++;
}
prev = current;
}
}
std::cout << counter << std::endl;
}