题解 | #字符串合并处理#
字符串合并处理
https://www.nowcoder.com/practice/d3d8e23870584782b3dd48f26cb39c8f
#include <cctype>
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
string sort_(string &str, string &str_1){
string a,b;
str += str_1;
for (int i = 0; i < str.size(); i += 2) a += str[i];
for (int i = 1; i < str.size(); i += 2) b += str[i];
sort(a.begin(), a.end());
sort(b.begin(), b.end());
str = "";
for (int i = 0; i < min(a.size(), b.size()); i++){
str += a[i];
str += b[i];
}
if (a.size() != b.size())
str += a.size() > b.size() ? a[a.size() - 1] : b[b.size() - 1];
return str;
}
void swag_(string &str){
char input[] = {"0123456789abcdefABCDEF"};
char output[] = {"084C2A6E195D3B7F5D3B7F"};
for (char& ch : str){
if (isdigit(ch) || (toupper(ch) >= 'A' && toupper(ch) <= 'F')){
if (isdigit(ch))
ch = output[ch - '0'];
else if(isupper(ch))
ch = output[ch - 'A' + 16];
else
ch = output[ch - 'a' + 10];
}
}
}
int main() {
string a, b;
while(cin>>a>>b){
string str = sort_(a, b);
swag_(str);
cout <<str;
}
}
// 64 位输出请用 printf("%lld")
查看13道真题和解析