day02a.cpp (466B)
1 #include <iostream> 2 #include <sstream> 3 #include <vector> 4 #include <algorithm> 5 #include <string> 6 using namespace std; 7 8 bool isvalid(const string &line) { 9 int x, y, b; 10 istringstream s(line); 11 12 s >> x >> y; 13 b = x > y ? 1 : -1; 14 do { 15 int d = b * (x-y); 16 if (d < 1 || d > 3) 17 return false; 18 x = y; 19 } while (s >> y); 20 21 return true; 22 } 23 24 int main() { 25 int tot = 0; 26 for (string line; getline(cin, line); ) 27 tot += isvalid(line); 28 cout << tot << endl; 29 return 0; 30 }