Run ID:115515
提交时间:2025-03-31 15:12:55
#include <iostream> #include <string> #include <algorithm> using namespace std; int countDigits(const string& str) { int count = 0; for (char c : str) { if (isdigit(c)) { count++; } } return count; } int main() { string str1, str2; getline(cin, str1); getline(cin, str2); int count1 = countDigits(str1); int count2 = countDigits(str2); // 确定数字最多的字符串和另一个字符串 string maxStr, otherStr; if (count1 >= count2) { maxStr = str1; otherStr = str2; } else { maxStr = str2; otherStr = str1; } reverse(otherStr.begin(), otherStr.end()); if (count1 > 0) { otherStr += maxStr[count1 - 1]; } cout << otherStr << endl; return 0; }