标签:hdu1223
one + two = three four + five six = zero seven + eight nine = zero + zero =
3 90 96
#include <stdio.h> #include <string.h> #define maxn 100 const char *sam[] = {"zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"}; char buf[maxn]; int calVal(char str[]) { for(int i = 0; i < 10; ++i) if(!strcmp(buf, sam[i])) return i; } int main() { int mode = 0, a[2]; a[0] = a[1] = 0; while(scanf("%s", buf) == 1) { if(!strcmp(buf, "+")) { ++mode; continue; } else if(!strcmp(buf, "=")) { if(a[0] + a[1] == 0) break; printf("%d\n", a[0] + a[1]); mode = a[0] = a[1] = 0; continue; } a[mode] = a[mode] * 10 + calVal(buf); } return 0; }
标签:hdu1223
原文地址:http://blog.csdn.net/chang_mu/article/details/40519301