hdoj1228 A+B

来源:互联网 发布:风云无双装备升级数据 编辑:程序博客网 时间:2024/05/18 00:58

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

水题一道

值得一提的是处理输入

while (cin >> str && str != "+") {
   A = A*10 + strtoi(str);
  }

#include <iostream>#include <string>using namespace std;string num[10] = {"zero","one","two","three","four","five","six",  "seven","eight","nine"};int strtoi(string str) {for (int i = 0; i < 10; i++) {if (str == num[i]) return i;}}int main(){string str;while (1) {int A = 0, B = 0;while (cin >> str && str != "+") {A = A*10 + strtoi(str);}while (cin >> str && str != "=") {B = B*10 + strtoi(str);}if (!A && !B) break;cout << A+B << endl;}return 0;}