/* MIDI Olympiad in Informatics 2007 * Untitled reference solution * by Adomas Paltanavicius */ /* Solution is to decode caesar script (shifting characters * left by one) and multiplying numbers. Of course, you * don't really have to do decoding in the program, * encoded words can be embedded into source instead. */ #include #include #include #include #define BUFSIZE 2048 char line[BUFSIZE]; const char sep[] = " \n\r"; int mult = 1; struct { char *name; int value; } names[] = { { "zero", 0 }, { "one", 1 }, { "two", 2 }, { "three", 3 }, { "four", 4 }, { "five", 5 }, { "six", 6 }, { "seven", 7 }, { "eight", 8 }, { "nine", 9 }, { NULL, 0 } }; void decrypt() { char *p; for (p = line; *p; p++) { if (!islower(*p)) *p = tolower(*p); if (*p >= 'a' && *p <= 'z') { if (*p == 'a') *p = 'z'; else --*p; } } } void calc() { char *word; for (word = strtok(line, sep); word; word = strtok(NULL, sep)) { int i; for (i = 0; names[i].name; i++) { if (strcmp(word, names[i].name) == 0) { mult *= names[i].value; break; } } } } int main() { freopen("untitled.in", "r", stdin); freopen("untitled.out", "w", stdout); fgets(line, BUFSIZE, stdin); decrypt(); calc(); printf("%d\n", mult); return 0; }