#include #include /* TODO */ #if 0 #define dpf(x) printf x #else #define dpf(x) (void)0 #endif #define dp dpf /* value of token */ int value(char *s) { int c = *s; int d = *(s + 1); int e = *(s + 2); if (c == 'z') return 0; if (c == 'o') return 1; if (c == 't') { if (d == 'w') { if (e == 'o') return 2; /* tw? */ s += 3; e = *s; if (e == 'l') return 12; return 20; } else if (d == 'h') { if (e == 'r') return 3; if (e == 'o') return 1000; s += 5; e = *s; return e == 'e' ? 13 : 30; } else if (d == 'e') return 10; } if (c == 'f') { if (d == 'o') { if (e == 'u') return *(s + 4) == 0 ? 4 : 14; return 40; } else if (d == 'i') { if (e == 'v') return 5; return *(s + 4) == 'y' ? 50 : 15; } } if (c == 's') { if (d == 'i') { s += 3; d = *s; e = *(s + 1); if (d == 0) return 6; if (e == 'e') return 16; return 60; } else if (d == 'e') { s += 5; d = *s; e = *(s + 1); if (d == 0) return 7; if (e == 'y') return 70; return 17; } } if (c == 'e') { if (d == 'l') return 11; s += 5; d = *s; if (d == 0) return 8; if (d == 'y') return 80; return 18; } if (c == 'n') { if (d == 'e') return -1; s +=4; d = *s; e = *(s + 1); if (d == 0) return 9; if (e == 'y') return 90; return 19; } if (c == 'm') return 1000000; return 100; } int main(void) { char str[100]; int x,y,z,neg,m; char *s, *ns; while (1) { gets(str); s = str; if (!*s) break; x = 0; z = 0; m = 0; while (1) { ns = strchr(s,' '); if (ns) { *ns = 0; ns++; } y = value(s); dp(("got %s %d\n",s,y)); if (y == -1) { neg = 1; } else if (y == 100) { /* if (x == 0) x = 1; */ x *= y; } else if (y > 100) { /* if (x == 0) x = 1; */ x *= y; z += x; x = 0; } else { x += y; } if (!ns) break; s = ns; while (*s == ' ') s++; } z += x; if (neg) z = -z; printf("%d\n",z); } return 0; }