随笔-13  评论-0  文章-2  trackbacks-0
ACM: HDU  1228

A + B

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 1801    Accepted Submission(s): 1135

Problem Description

读入两个小于100的正整数A和B,计算A+B.
需要注意的是:A和B的每一位数字由对应的英文单词给出.

Input

测试输入包含若干测试用例,每个测试用例占一行,格式为"A + B =",相邻两字符串有一个空格间隔.当A和B同时为0时输入结束,相应的结果不要输出.

Output

对每个测试用例输出1行,即A+B的值.

Sample Input

one + two =three four + five six = zero seven + eight nine =zero + zero =

 

Sample Output

39096


 1/**
 2* Title: A + B   
 3* Problem URL: http://acm.hdu.edu.cn/showproblem.php?pid=1228   
 4* Author: Fleap  
 5* Date: 2009-02-16   
 6* Accepted 1228 0MS 0K 826 B C moqi 
 7**/

 8#include<iostream>
 9#include<sstream>
10#include<map>
11#include<string>
12int main()
13{
14     using namespace std;
15     map<stringint> num;
16     num["zero"= 0;
17     num["one"= 1;
18     num["two"= 2;
19     num["three"= 3;
20     num["four"= 4;
21     num["five"= 5;
22     num["six"= 6;
23     num["seven"= 7;
24     num["eight"= 8;
25     num["nine"= 9;

26     string line;
27     while( getline(cin , line) )
28     {
29              istringstream s(line);
30              int a = 0, b = 0;
31              while( s >> line )
32              {
33                     if( line == "+" ) break;
34                a += num[line];
35                a *= 10
36           }

37           while( s >> line )
38           {
39                     if( line == "=" ) break;
40                     b += num[line];
41                     b *= 10;
42           }

43           
44           if( a + b == 0break;
45           else cout << (a + b) / 10 << endl;
46    }

47    
48     return 0;
49}

50
posted on 2009-02-16 23:23 亦夏 阅读(343) 评论(0)  编辑 收藏 引用 所属分类: ACM

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理