C++代码
- /*
- Title: A + B
- Problem URL: http://acm.hdu.edu.cn/showproblem.php?pid=1228
- Author: Moqi
- Date: 2008-03-19
- Description:505495 2008-03-19 20:33:48 Accepted 1228 0MS 0K 826 B C moqi
- */
- #include <stdio.h>
- #include <math.h>
- int main()
- {
- int s, a, i, j;
- char line[1024];
- char num[10][5] = {"zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"};
- while (gets(line))
- {
- s = j = 0;
- a = 0;
- while (line[j] != ‘=’)
- {
- for (i = 0; i < 10; i++)
- {
- if (line[j] == num[i][0] && line[j+1] == num[i][1])
- {
- a += i;
- while(line[j] != ‘ ‘)
- j++;
- break;
- }
- }
- j++;
- if (line[j] == ‘+’)
- {
- s += a;
- a = 0;
- j += 2;
- }
- else if (line[j] != ‘=’)
- {
- a *= 10;
- }
- }
- if (s != 0 || a != 0)
- printf("%d\n", s + a);
- }
- return 0;
- }