题解 | #字符串合并处理#
字符串合并处理
https://www.nowcoder.com/practice/d3d8e23870584782b3dd48f26cb39c8f
#include <algorithm>
#include <cctype>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main() {
string s1, s2; //0110
string str1 = "0123456789abcedfABCEDF";
string str2 = "084C2A6E195D37BF5D37BF";
while (cin >> s1 >> s2) {
vector<char> v1(s1.size()), v2(s2.size());
string strOout = s1 + s2;
string odd, even;
for (int i = 0; i < strOout.size(); i++) {
if (i % 2 == 0) {
even += strOout[i];
} else {
odd += strOout[i];
}
}
sort(odd.begin(), odd.end());
sort(even.begin(), even.end());
//cout <<odd << ":" <<even<<endl;
for (int i = 0, j = 0, l = 0; i < strOout.size(); i++) {
if (i % 2 == 0) {
strOout[i] = even[j++];
} else {
strOout[i] = odd[l++];
}
if ((strOout[i] >= '0' && strOout[i] <= '9') || (toupper(strOout[i]) >= 'A' &&
toupper(strOout[i]) <= 'F')) {
strOout[i] = str2[str1.find_last_of(strOout[i])];
}
}
cout << strOout << endl;
}
}
// 64 位输出请用 printf("%lld")


