题解 | #字符串加密#

字符串加密

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

#include<iostream>
#include<string>
#include<cstring>
#include<vector>
#include<unordered_set>
using namespace std;

const int N = 105;
int h[26];
char th[26];

vector<char> v;
unordered_set<char> us;


int main() {
    string s, m;
    cin >> s;
    cin >> m;

    for (char c : s) {
        h[c - 'a']++;
        if (us.count(c) == 0) {
            us.insert(c);
            v.push_back(c);
        } 
    }

    string left = "", res = "";
    for (auto it = v.begin(); it != v.end(); it ++) res += *it;

    for (int i = 0; i < 26; i++) {
        if (!h[i]) left += i + 'a';
    }
    res += left;

    int cnt = 0;
    for (char c : res) {
        th[cnt++] = c;
    }
    for (char c : m) {
        cout << th[c - 'a'];
    }

    return 0;
}

全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

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