hdu 1228 A+B 字符串处理 超级大水题
2013-07-14 00:41
381 查看
中文意思不解释。
很水,我本来想用switch处理字符串,然后编译不通过。。。原来switch只能处理整数型的啊,我都忘了。
然后就有了很挫的一大串if代码了。。。
代码:
很水,我本来想用switch处理字符串,然后编译不通过。。。原来switch只能处理整数型的啊,我都忘了。
然后就有了很挫的一大串if代码了。。。
代码:
#include <iostream> #include <string> using namespace std; int digit(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 getval() { string tmp; int s = 0; while (cin >> tmp && tmp != "+" && tmp != "=") { s = s * 10 + digit(tmp); // cout << tmp << endl; } return s; } int main() { int p1, p2; while (1) { p1 = getval(); p2 = getval(); // cout << p1 << " + " << p2 << " = "<< endl; if (p1 == 0 && p2 == 0) break; cout << p1 + p2 << endl; }//while return 0; }
相关文章推荐
- hdu 1228 A+B 字符串处理 超级大水题
- HDU-1228-A + B(简单字符串处理)
- hdu 1228 A+B (字符串处理) 水
- HDU 1004 字符串处理 大水题啊
- HDU-1228-A+B(字符串处理)
- [ACM] hdu 1228 A+B (字符串处理)
- hdu 1228 A+B【字符串处理】
- HDU 5284 wyh2000 and a string problem——BestCoder Round #48(普通的字符串处理)
- HDU 1073 Online Judge (字符串处理,简单题)
- 简单字符串处理 hdu1062 Text Reverse
- HDU 2072 字符串处理(判重)
- HDU 4891 The Great Pan (字符串处理)
- HDU-5938 Four Operations(字符串处理)
- HDU 5414 CRB and String(字符串处理)——多校练习10
- hdu 1229 超级大水题
- hdu 3787 A+B(简单字符串处理)
- HDU 3746---用KMP处理字符串
- hdu 2206IP的计算(sscanf的使用 & 字符串判断处理)
- 【W】HDU2206——字符串处理(IP计算)
- 杭电HDU 4550 字符串处理