#include #include #define MAX_LENGTH 165 int main(void) { char buf[MAX_LENGTH]; int game_num, cubes, sum; sum = 0; while (fgets(buf, MAX_LENGTH, stdin)) { char* c = buf; game_num = strtol(c + 5, &c, 10); // +5 skips the "Game " while (*c != '\n') { cubes = strtol(c + 2, &c, 10); // +2 skips ": ", ", ", or "; " c++; // +1 skips the space if ((*c == 'r' && cubes > 12) || (*c == 'g' && cubes > 13) || (*c == 'b' && cubes > 14)) { game_num = 0; } for (; *c >= 'a' && *c <= 'z'; c++); } sum += game_num; } printf("%d\n", sum); return 0; }