# 题解 | #字符串合并处理#

https://www.nowcoder.com/practice/d3d8e23870584782b3dd48f26cb39c8f

```#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>
using namespace std;

string strMerge(string s1, string s2)
{
string s = s1 + s2;
vector<char> odd;
vector<char> even;
size_t len = s.length();

for (size_t i=0; i<len; i++)
{
if (i%2 == 0)
{
odd.push_back(s[i]);
}
else
{
even.push_back(s[i]);
}
}

sort(odd.begin(), odd.end());
sort(even.begin(), even.end());

s.clear();
int p = 0;
int q = 0;
for (size_t i=0; i<len; i++)
{
if (i%2 == 0)
{
s.push_back(odd[p++]);
}
else
{
s.push_back(even[q++]);
}
}

return s;
}

char IntReverse(char ch)
{
string s;
int val;

if (ch >= '0' && ch <= '9')
{
val = ch - '0';
}
else if (ch >= 'a' && ch <= 'f')
{
val = ch - 'a' + 10;
}
else if (ch >= 'A' && ch <= 'F')
{
val = ch - 'A' + 10;
}
else
{
return ch;
}

while (val > 0)
{
char ch = (val % 2 == 1) ? '1' : '0';
s.push_back(ch);
val /= 2;
}

while (s.length() < 4)
{
s.push_back('0');
}

int i = 0;
int sum = 0;
for (auto it = s.rbegin(); it<s.rend(); it++)
{
sum += (*it-'0') * int(pow(2, i));
i++;
}

if (sum < 10)
{
return '0' + sum;
}

return 'A' + sum - 10;
}

int main() {
string s1, s2;

cin >> s1 >> s2;
string s = strMerge(s1, s2);

for (char ch : s)
{
cout << IntReverse(ch);
}

cout << endl;
return 0;
}
// 64 位输出请用 printf("%lld")
```