#include #include #include #include "solutions.hpp" using namespace std; template <> pair solve<2>(istream& input) { uint64_t part1 = 0, part2 = 0; for (string line; getline(input, line); ) { stringstream line_stream(line); uint64_t min_count, max_count; char target; string password; line_stream >> min_count; if (line_stream.get() != (int) '-') { throw domain_error("input incorrect"); } line_stream >> max_count; if (line_stream.get() != (int) ' ') { throw domain_error("input incorrect"); } line_stream >> target; if (line_stream.get() != (int) ':') { throw domain_error("input incorrect"); } if (line_stream.get() != (int) ' ') { throw domain_error("input incorrect"); } line_stream >> password; size_t count = 0; for (char c : password) { count+=(int)(c == target); } part1 += (int)(count >= min_count && count <= max_count); part2 += (int)((password[min_count - 1] == target) != (password[max_count - 1] == target)); } return pair(to_string(part1), to_string(part2)); }