hdoj1228 A+B

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

你可能感兴趣的:(hdoj1228 A+B)