现在的位置: 首页 > 综合 > 正文

hdoj1228 A+B

2018年04月02日 ⁄ 综合 ⁄ 共 495字 ⁄ 字号 评论关闭

题目链接: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;
}

抱歉!评论已关闭.