2-1: I have quickly run out of hecks to give. This is the sort of problem that gives prolog programmers feelings of smug superiority.
spoiler
#include <string>
#include <iostream>
#include <sstream>
int main() {
int safe = 0;
std::string s;
while (std::getline(std::cin, s)) {
std::istringstream iss(s);
int a, b, c;
if (!(iss >> a >> b)) {
safe++; continue;
}
if (a == b || std::abs(a-b) > 3) continue;
bool increasing = b > a;
while (iss >> c) {
if (b == c || std::abs(b-c) > 3) goto structuredprogrammingisfornerds;
switch (increasing) {
case false:
if (c < b) { b = c; continue; }
goto structuredprogrammingisfornerds;
case true:
if(c > b) { b = c; continue; }
goto structuredprogrammingisfornerds;
}
}
safe++;
structuredprogrammingisfornerds:;
}
std::cout << safe << std::endl;
}
As usual the second part has punished me for my cowboy code, so I'll have to take a different more annoying tack (maybe tomorrow). Or you know I could just double down on the haphazard approach...