九度OnlineJudge之1010 A + B
来源:互联网 发布:h3c mac acl 编辑:程序博客网 时间:2024/05/18 01:03
题目描述:
读入两个小于100的正整数A和B,计算A+B.
需要注意的是:A和B的每一位数字由对应的英文单词给出.
需要注意的是:A和B的每一位数字由对应的英文单词给出.
- 输入:
- 测试输入包含若干测试用例,每个测试用例占一行,格式为"A + B =",相邻两字符串有一个空格间隔.当A和B同时为0时输入结束,相应的结果不要输出.
- 输出:
- 对每个测试用例输出1行,即A+B的值.
- 样例输入:
one + two =three four + five six =zero seven + eight nine =zero + zero =
- 样例输出:
39096
#include <iostream>#include <string>#include <vector>#include <cmath>using namespace std;inline int getInt(string str){if (str=="zero") return 0;if (str=="one") return 1;if (str=="two") return 2;if (str=="three") return 3;if (str=="four") return 4;if (str=="five") return 5;if (str=="six") return 6;if (str=="seven") return 7;if (str=="eight") return 8;if (str=="nine") return 9;return -1;}int main(){vector<string> vec1,vec2;vector<string>::iterator it; string tmp1,tmp2;int A,B;while(true){A=0; B=0;vec1.clear();vec2.clear();while(cin>>tmp1,tmp1!="+") vec1.push_back(tmp1);while(cin>>tmp2,tmp2!="=") vec2.push_back(tmp2);int len1 = vec1.size();int len2 = vec2.size(); bool flag = (*(vec1.begin())=="zero" && *(vec2.begin())=="zero" &&len1==1 &&len2==1); if (flag) break;for (int i=0;i<len1;i++){A = A + getInt(vec1[i]) * (int)pow(10.0,(double)len1-1-i);}for (int i=0;i<len2;i++){B = B + getInt(vec2[i]) * (int)pow(10.0,(double)len2-1-i);}cout<<A+B<<endl;}//system("pause");return 0;}
- 九度OnlineJudge之1010 A + B
- 九度OnlineJudge之1003:A+B
- 九度OnlineJudge之1001:A+B for Matrices
- 九度OnlineJudge题目1015:还是A+B
- 九度OnlineJudge题目1026:又一版 A+B
- 九度OnlineJudge之1468:Sharing
- 九度OnlineJudge之1002:Grading
- 九度OnlineJudge之1004:Median
- 九度OnlineJudge之1012:畅通工程
- 九度OnlineJudge之1014:排名
- 九度OnlineJudge之1020:最小长方形
- 九度OnlineJudge之1021:统计字符
- 九度OnlineJudge之1022:游船出租
- 九度OnlineJudge之1023:EXCEL排序
- 九度OnlineJudge之1032:ZOJ
- 九度OnlineJudge之1034:寻找大富翁
- 九度OnlineJudge之1036:Old Bill
- 九度1010 A + B
- 面试题目搜集(5)
- 【设计模式】抽象工厂
- Arduino的数据类型
- 关于软件设计的一点感想2
- DDL/DML操作在Read committed和Serializable 事务隔离等级中的示例
- 九度OnlineJudge之1010 A + B
- iOS中 block 导致 reference loop "引用循环" 引起的leak
- 最长重复子串——后缀数组
- 【转】【环境搭建】Ubuntu安装Boost
- VC使用gdiplus加载图像的方法
- 自定义UINavigationController背景-按钮-标题。5.0前后兼容
- iOS应用程序生命周期(前后台切换,应用的各种状态)详解
- Android开发9:UI组件ImageView
- Poj 1094 Sorting It All Out (传递闭包+拓扑排序)