#include char cisla[20][20] = { "zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten", "eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eighteen", "nineteen" }; char desiatky[8][20] = { "twenty", "thirty", "forty", "fifty", "sixty", "seventy", "eighty", "ninety" }; char sto[] = "hundred", tisic[] = "thousand", milion[] = "million"; int pole[20]; int main() { char vstup[500], *retazec, co[20]; int i, j, cislo[3], c, pom; for (i = 0; i < 500; i++) vstup[i] = 0; gets(vstup); while (vstup[0] != 0) { j = 0; retazec = vstup; sscanf(retazec, "%s", co); while (retazec[0] != 0) { if (!strcmp("negative", co)) { printf("-"); retazec += strlen(co); if (retazec[0] == ' ') retazec++; sscanf(retazec, "%s", co); continue; } i = 0; while (i < 20 && strcmp(cisla[i], co)) i++; if (i < 20) { pole[j++] = i; retazec += strlen(co); if (retazec[0] == ' ') retazec++; sscanf(retazec, "%s", co); continue; } i = 0; while (i < 8 && strcmp(desiatky[i], co)) i++; if (i < 8) { pole[j++] = (i + 2) * 10; retazec += strlen(co); if (retazec[0] == ' ') retazec++; sscanf(retazec, "%s", co); continue; } if (!strcmp(sto, co)) { pole[j++] = 100; retazec += strlen(co); if (retazec[0] == ' ') retazec++; sscanf(retazec, "%s", co); continue; } if (!strcmp(tisic, co)) { pole[j++] = 1000; retazec += strlen(co); if (retazec[0] == ' ') retazec++; sscanf(retazec, "%s", co); continue; } if (!strcmp(milion, co)) { pole[j++] = 1000000; retazec += strlen(co); if (retazec[0] == ' ') retazec++; sscanf(retazec, "%s", co); continue; } } cislo[0] = cislo[1] = cislo[2] = pom = 0; c = 0; int treba; for (i = 0; i < j; i++) { if (pole[i] < 100) { pom += pole[i]; treba = 1; } else { if (pole[i] == 1000) { cislo[1] = pom * pole[i]; pom = 0; } if (pole[i] == 1000000) { cislo[2] = pom * pole[i]; pom = 0; } else pom *= pole[i]; treba = 0; } } printf("%d\n", cislo[2] + cislo[1] + pom); for (i = 0; i < 500; i++) vstup[i] = 0; gets(vstup); } return 0; }