HDU1228 A+B 字符串模拟题

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1228


实现代码如下:

#include <cstdio>
#include <iostream>
#include <cstring>
using namespace std;
char num[10][10]={"zero","one","two","three","four","five","six","seven","eight","nine"};
int change(char *str1)
{
    for(int i=0;i<10;i++)
      if(strcmp(num[i],str1)==0)
        return i;
}
int main()
{
    char str[30],str1[10];
    while(gets(str))
    {
        int cnt,i=0,a=0,b=0;
        while(str[i]!='+')
        {
            cnt=0;
            for(;str[i]!=' ';i++)
              str1[cnt++]=str[i];
            str1[cnt]='\0';
            a=a*10+change(str1);
            i++;
            //printf("a=%d\n",a);
        }
        i+=2;
        while(str[i]!='=')
        {
            cnt=0;
            for(;str[i]!=' ';i++)
              str1[cnt++]=str[i];
            str1[cnt]='\0';
            b=b*10+change(str1);
            i++;
            //printf("b=%d\n",b);
        }
        if(a==0&&b==0) break;
        else printf("%d\n",a+b);
    }
}



你可能感兴趣的:(HDU1228 A+B 字符串模拟题)