Hdu 1128 A+B

简单模拟题。代码有点乱,感觉自己实现起来也有点麻烦。要加大力度练习啦!~

CODE:

#include <stdio.h>
#include <stdlib.h>
#include < string.h>
using  namespace std;

const  int maxn =  101;
char str[ 11][ 20] = { " zero "" one "" two "" three "" four "" five "" six "" seven "" eight "" nine "};
char word[ 11][ 11];
char s[maxn];
int cnt;


int cmp( char *s)   // 查找 
{
     for( int i =  0 ; i <  10 ; i++)
    {
         if(strcmp(s, str[i]) ==  0return i;
    }
     return - 1;
}


void init( char *s)          // 将数字保存进字符二维数组中 
{
     char save[ 21];
     int i, j;
     int l = strlen(s);
     int tot =  0;
    cnt =  0;
     for(i =  0 ; i < l; i++)
    {
         if(s[i] ==  '   ')
        {
            save[tot] =  ' \0 ';
            strcpy(word[cnt++], save);
            tot =  0;
        }
         else
        {
            save[tot++] = s[i];
        }
    }
}


int  get()
{
     int a =  0, b =  0;
     int t;
     int i =  0;
     while(i < cnt)
    {
         if(cmp(word[i]) == - 1break// 接收'+' 
        a = a* 10 + cmp(word[i++]);
    }
    i++;
     while(i < cnt)
    {
         if(cmp(word[i]) == - 1break;   // 接收'=' 
        b = b* 10 + cmp(word[i++]);

    }
     return a+b;
}


int main()
{
     while(fgets(s, maxn, stdin))        // fgets(s, maxn, stdin);
    {
        memset(word,  0sizeof(word));
        init(s);
         int m =  get();
         if(!m)  break;
        printf( " %d\n ", m);
    }
     return  0;

} 

转载于:https://www.cnblogs.com/g0feng/archive/2012/07/20/2600963.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值