c++题解 | #字符串合并处理 30行代码#

字符串合并处理

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

#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main(){
    string str, str1, str2;
    string a("0123456789abcdefABCDEF");
    string b("084C2A6E195D3B7F5D3B7F");
    cin >> str1 >> str2;
    str = str1 + str2;
    str1.clear(); str2.clear();
    for(int i = 0; i < str.size(); ++i)
        if(i % 2 == 0)
            str1 += str[i];
        else
            str2 += str[i];
    sort(str1.begin(), str1.end());
    sort(str2.begin(), str2.end());
    for(int i = 0; i < str.size(); ++i)
        if(i % 2 == 0)
            str[i] = str1[i/2];
        else
            str[i] = str2[(i-1)/2];
    for(int i = 0; i < str.size(); ++i){
        int n = a.find_first_of(str[i]);
        if(n != -1)
            str[i] = b[n];
    }
    cout << str;
}
全部评论

相关推荐

西松屋:说明原部门有机会把
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务