55 lines
1.2 KiB
C++
55 lines
1.2 KiB
C++
|
#include <iostream>
|
||
|
#include <algorithm>
|
||
|
#include <vector>
|
||
|
#include <sstream>
|
||
|
|
||
|
class report {
|
||
|
std::vector<int> levels;
|
||
|
public:
|
||
|
bool safe();
|
||
|
friend std::istream& operator>>(std::istream& stream, report& r);
|
||
|
friend std::ostream& operator<<(std::ostream& stream, report& r);
|
||
|
};
|
||
|
|
||
|
std::istream& operator>>(std::istream& stream, report& r) {
|
||
|
r.levels.clear();
|
||
|
std::string s;
|
||
|
std::getline(stream, s, '\n');
|
||
|
std::stringstream ss(s);
|
||
|
int level;
|
||
|
while (ss >> level) {
|
||
|
r.levels.emplace_back(level);
|
||
|
}
|
||
|
return stream;
|
||
|
}
|
||
|
|
||
|
std::ostream& operator<<(std::ostream& stream, report& r) {
|
||
|
stream << "report{";
|
||
|
for (auto elem : r.levels) {
|
||
|
stream << elem << ",";
|
||
|
}
|
||
|
stream << "}";
|
||
|
return stream;
|
||
|
}
|
||
|
|
||
|
bool report::safe() {
|
||
|
return std::adjacent_find(levels.begin(), levels.end(), [](int a, int b) {
|
||
|
return a - b < 1 || a - b > 3;
|
||
|
}) == levels.end()
|
||
|
|| std::adjacent_find(levels.begin(), levels.end(), [](int a, int b) {
|
||
|
return b - a < 1 || b - a > 3;
|
||
|
}) == levels.end();
|
||
|
}
|
||
|
|
||
|
int main() {
|
||
|
report r;
|
||
|
int count = 0;
|
||
|
while (std::cin >> r) {
|
||
|
if (r.safe()) {
|
||
|
count++;
|
||
|
}
|
||
|
}
|
||
|
std::cout << count << std::endl;
|
||
|
return EXIT_SUCCESS;
|
||
|
}
|