HDOJ 1228 A + B

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


水题~~~

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
// Accepted 1228 0MS 200K 641 B C++ 
#include <iostream>
#include <cmath>
using namespace std;
char map[][10] = {"zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"};
int search(char s[])
{
    for(int i=0; i<10; i++)
        if (strcmp(s,map[i])==0)
            return i;
}
int main()
{    
    char s[10];
    int a, b;
    while (1)
    {
        a=0;
        while (scanf("%s", s) && strcmp(s, "+") !=0 )
            a= a*10 + search(s);
        b=0;
        while (scanf("%s", s) && strcmp(s, "=") !=0)
            b= b*10 + search(s);
        if( a==0 && b==0)    break;
        printf("%d\n", a+b);
    }
    return 0;
}

发布者

Tanky Woo

Tanky Woo,[个人主页:https://tankywoo.com] / [新博客:https://blog.tankywoo.com]

发表评论

电子邮件地址不会被公开。 必填项已用*标注