Chinaunix首页 | 论坛 | 博客
  • 博客访问: 59186
  • 博文数量: 29
  • 博客积分: 667
  • 博客等级: 上士
  • 技术积分: 300
  • 用 户 组: 普通用户
  • 注册时间: 2010-04-11 15:55
文章分类
文章存档

2012年(2)

2011年(27)

我的朋友
最近访客

分类: C/C++

2011-10-06 14:38:28

  1. //Gurad的代码
  2. #include<stdio.h>
  3. #include<string.h>

  4. char *num[10] = {"zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"};
  5. int numTran(char a[])
  6. {
  7.     for(int i = 0; i < 10; i++)
  8.         if(!strcmp(a, num[i]))
  9.             return i;
  10.     return 0;
  11. }

  12. int main()
  13. {
  14.     char equl[50];
  15.     char numa[10];
  16.     char numb[10];
  17.     char numc[10];
  18.     char numd[10];
  19.     while(1)
  20.     {
  21.         gets(equl);
  22.         memset(numa, 0, 10);
  23.         memset(numb, 0, 10);
  24.         memset(numc, 0, 10);
  25.         memset(numd, 0, 10);
  26.         int i, j, k;
  27.         int isDoubleA, isDoubleB;
  28.         isDoubleA = isDoubleB = 0;
  29.         for(i = 0; equl[i] != '+'; i++)
  30.             ;
  31.         for(j = 0; equl[j] != ' '; j++)
  32.             numa[j] = equl[j];//a
  33.         numa[j] = '\0';

  34.         for(k = j + 1; k < i - 1; k++)
  35.         {
  36.             isDoubleA = 1;
  37.             numb[k - j - 1] = equl[k];
  38.         }
  39.         numb[k - j - 1] = '\0';//b

  40.         for(; equl[i] != '='; i++)
  41.             ;

  42.         if(isDoubleA)
  43.             k += 3;
  44.         else
  45.             k += 2;

  46.         for( j = k; equl[j] != ' '; j++)
  47.             numc[j - k] = equl[j];//c
  48.         numc[j - k] = '\0';

  49.         for(k = j + 1; k < i - 1; k++)
  50.         {
  51.             isDoubleB =1;
  52.             numd[k - j - 1] = equl[k];//d
  53.         }
  54.         numd[k - j - 1] = '\0';

  55.         int a = numTran(numa);
  56.         if(isDoubleA)
  57.         {
  58.             
  59.             a = a*10 + numTran(numb);
  60.             //printf("%d\n", numTran(numb));
  61.         }

  62.         int b = numTran(numc);
  63.         if(isDoubleB)
  64.         {
  65.             b = b*10 + numTran(numd);
  66.             //printf("%d\n", numTran(numd));
  67.         }
  68.         if(a == 0 && b == 0)
  69.             break;

  70.         printf("%d\n", a + b);        
  71.     }
  72.     return 0;
  73. }
阅读(714) | 评论(0) | 转发(0) |
0

上一篇:素数筛法

下一篇:简单工厂模式

给主人留下些什么吧!~~