C++代码
  1. /*  
  2. Title: A + B  
  3. Problem URL: http://acm.hdu.edu.cn/showproblem.php?pid=1228  
  4. Author: Moqi  
  5. Date: 2008-03-19  
  6. Description:505495 2008-03-19 20:33:48 Accepted 1228 0MS 0K 826 B C moqi   
  7. */  
  8. #include <stdio.h>   
  9. #include <math.h>   
  10. int main()   
  11. {   
  12.     int s, a, i, j;   
  13.     char line[1024];   
  14.     char num[10][5] = {"zero""one""two""three""four""five""six""seven""eight""nine"};   
  15.     while (gets(line))   
  16.     {   
  17.         s = j = 0;   
  18.         a = 0;   
  19.         while (line[j] != ‘=’)   
  20.         {   
  21.             for (i = 0; i < 10; i++)   
  22.             {   
  23.                 if (line[j] == num[i][0] && line[j+1] == num[i][1])   
  24.                 {   
  25.                     a += i;   
  26.                     while(line[j] != ‘ ‘)   
  27.                         j++;   
  28.                     break;   
  29.                 }   
  30.             }   
  31.             j++;   
  32.             if (line[j] == ‘+’)   
  33.             {   
  34.                 s += a;   
  35.                 a = 0;   
  36.                 j += 2;   
  37.             }   
  38.             else if (line[j] != ‘=’)   
  39.             {   
  40.                 a *= 10;   
  41.             }   
  42.         }   
  43.         if (s != 0 || a != 0)   
  44.             printf("%d\n", s + a);   
  45.     }   
  46.     return 0;   
  47. }