题解 | #字符串合并处理#
字符串合并处理
http://www.nowcoder.com/practice/d3d8e23870584782b3dd48f26cb39c8f
输入输出流和bitset来做
#include<bits/stdc++.h>
//#include <cctype>
using namespace std;
map<char,char>t = {{1,2},{}};
int main(){
string s1,s2;
cin>>s1>>s2;
string s = s1+s2;
s1="";s2="";
for(int i = 0; 2*i < s.size();i++){
s1+=(s[2*i]);
if(2*i+1<s.size())
s2+=(s[2*i+1]);
}
sort(s1.begin(),s1.end());
sort(s2.begin(), s2.end());
for(int i = 0; 2*i < s.size();i++){
s[2*i] = s1[i];
if(2*i+1<s.size())
s[2*i+1] = s2[i];
}
string res ="";
for(auto c: s){
if((c>='0'&&c<='9') || (c>='a' &&c<='f') || (c>='A' &&c<='F'))
{
bitset<4> bits(stoi(string (1,c), nullptr, 16));
string tmp = bits.to_string();
reverse(tmp.begin(),tmp.end());
stringstream ss;
string hex;
ss<<hex<<std::hex<<stoi(tmp, nullptr, 2);
ss>>hex;
transform(hex.begin(), hex.end(),hex.begin(),::toupper);
res+=hex;
}
else
res+=c;
}
cout<<res<<endl;
}
