题解 | #字符串加密#

字符串加密

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

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

int main() {
    vector<char> vec;
    vector<bool> vecflag(26, false);

    string input;
    string key;

    cin >> key >> input;
    for (auto c : key) {
        char cc = tolower(c);
        if (!vecflag[cc - 'a']) {
            vec.push_back(cc);
            vecflag[cc - 'a'] = true;
        }
    }
    for (char c = 'a'; c <= 'z'; c++) {
        if (!vecflag[c - 'a'] ) {
            vec.push_back(c);
            vecflag[c - 'a'] = true;
        }
    }

    string output = "";
    for (auto sc : input) {
        if (islower(sc)) {
            output += vec[sc - 'a'];
        } else {
            output += vec[sc - 'A'] - 32;
        }
    }
    cout << output << endl;

    // for (auto c : vec) {
    //     cout << c << " ";
    // }
    // cout << endl << "vec.size():" << vec.size() << endl;




}

全部评论

相关推荐

11-03 14:38
重庆大学 Java
AAA求offer教程:我手都抬起来了又揣裤兜了
点赞 评论 收藏
分享
评论
点赞
收藏
分享
牛客网
牛客企业服务