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

字符串合并处理

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

#include <bits/stdc++.h>
using namespace std;

int main() {
    string str, str1, str2;
    cin >> str1 >> str2;
    str = str1 + str2;
    string sg, db;
    for (int i = 0; i < str.length(); i++) {
        if (i % 2 == 0) {
            db += str[i];
        } else if (i % 2 == 1) {
            sg += str[i];
        }
    }
    sort(sg.begin(), sg.end());
    sort(db.begin(), db.end());
    int j = 0;
    int k = 0;
    for (int i = 0; i < str.size(); i++) {
        if (i % 2 == 0) {
            str[i] = db[j];
            j++;
        } else if (i % 2 == 1) {
            str[i] = sg[k];
            k++;
        }
    }
    string Output = {"084C2A6E195D3B7F5D3B7F"};
    for (int i = 0; i < str.size(); i++) {
        if ((str[i] >= '0') && (str[i] <= '9')) {
            str[i] = Output[str[i] - '0'];
        } else if ((str[i] >= 'a') && (str[i] <= 'f')) {
            str[i] = Output[str[i] - 'a' + 10];
        } else if ((str[i] >= 'A') && (str[i] <= 'F')) {
            str[i] = Output[str[i] - 'A' + 16];
        }
    }
    cout << str << endl;
}

全部评论

相关推荐

11-20 13:39
已编辑
门头沟学院 Java
点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务