题解 | #字符串合并处理#
字符串合并处理
https://www.nowcoder.com/practice/d3d8e23870584782b3dd48f26cb39c8f
#include <iostream>
#include <vector>
#include <algorithm>
#include <math.h>
using namespace std;
void Sort(string& arr, int n) {
string temp;
int j = 0;
for (int i = n; i < arr.size(); i = i + 2) {
temp = temp + arr[i];
}
sort(temp.begin(), temp.end());
for (int i = n; i < arr.size(); i = i + 2) {
arr[i] = temp[j];
j++;
}
}
char solvenu(int temp) {
int nu = 1;
string t;
int change = 0;
char r;
for (int i = 0; i < 4; i++) {
if (nu & temp) {
t = t + '1';
} else {
t = t + '0';
}
nu = nu << 1;
}
int count = 3;
for (auto a : t) {
change = change + (a - '0') * pow(2, count);
count--;
}
if (change < 10) {
r = ('0' + change);
} else {
r = ('A' + (change - 10));
}
return r;
}
int main() {
string str, str1, str2;
vector<char> arr1, arr2;
cin >> str1 >> str2;
str = str1 + str2;
Sort(str, 1);
Sort(str, 0);
string res;
for (auto a : str) {
if (a <= '9' && a >= '0') {
int temp = a - '0';
res = res + solvenu(temp);
} else if (a <= 'f' && a >= 'a') {
int temp = a - 'a' + 10;
res = res + solvenu(temp);
} else if (a <= 'F' && a >= 'A') {
int temp = a - 'A' + 10;
res = res + solvenu(temp);
} else {
res += a;
}
}
cout << res;
}


