标签:des name blank date 示例 格式 cout 测试 pre
测试输入包含若干测试用例,每个测试用例占一行,格式为"A + B =",相邻两字符串有一个空格间隔.当A和B同时为0时输入结束,相应的结果不要输出.
对每个测试用例输出1行,即A+B的值.
one + two = three four + five six = zero seven + eight nine = zero + zero =
3 90 96
/* * @Qusetion: https://dwz.lc/iiYuaA2eO * @Author: 一届书生 * @Date: 2020-03-19 10:13:14 * @LastEditTime: 2020-03-21 23:54:26 */ #include <iostream> #include <string> #include <map> using namespace std; char s[50]; int main() { map<string, int> mp{{"one", 1}, {"two", 2}, {"three", 3}, {"four", 4}, {"five", 5}, {"six", 6}, {"seven", 7}, {"eight", 8}, {"nine", 9}, {"zero", 0}}; while (gets(s)) { string t[10]; for (int i = 0, j = 0; i < 50; i++) { if (s[i] == ‘ ‘) j++; else t[j] += s[i]; } if (t[0] == t[2] && t[2] == "zero") return 0; // *+* if (t[1] == "+" && t[3][0] == ‘=‘) cout << mp[t[0]] + mp[t[2]] << endl; // *+** if (t[1] == "+" && t[4][0] == ‘=‘) cout << mp[t[0]] + mp[t[2]] * 10 + mp[t[3]] << endl; // **+* if (t[2] == "+" && t[3][0] == ‘=‘) cout << mp[t[0]] * 10 + mp[t[1]] + mp[t[3]] << endl; // **+** if (t[2] == "+" && t[5][0] == ‘=‘) cout << mp[t[0]] * 10 + mp[t[1]] + mp[t[3]] * 10 + mp[t[4]] << endl; } return 0; }
标签:des name blank date 示例 格式 cout 测试 pre
原文地址:https://www.cnblogs.com/52dxer/p/12543493.html