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;
}
全部评论

相关推荐

想申请延毕了,找工作找到崩溃,越找就越想摆烂,还有25届的和我一样感受吗?
码农索隆:没事哒,好兄弟,慢慢来,调整心态,车到山前必有路,感到迷茫的时候,多抬头看看
点赞 评论 收藏
分享
05-12 16:04
已编辑
江西财经大学 Java
点赞 评论 收藏
分享
吴offer选手:学到了,下次面试也放张纸在电脑上,不然老是忘记要说哪几个点
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务