题解 | #字符串加密#

字符串加密

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

#include <iostream>
#include <map>

using namespace std;

string ch = "abcdefghijklmnopqrstuvwxyz";

int main(){
    string key,str;
    while (cin>>key>>str) {
        map<char,bool> mp;
        string newkey;
        for (int i = 0; i < ch.size(); ++i) {
            mp[ch[i]] = false;
        }
        for (int i = 0; i < key.size(); ++i) {
            if (!mp[key[i]]){
                newkey += key[i];
                mp[key[i]] = true;
            }
        }
        for(auto it : mp){
            if (!it.second) {
                newkey += it.first;
            }
        }
        for (int i = 0; i < str.size(); ++i) {
            str[i] = newkey[str[i]-'a'];
        }
        cout<<str<<endl;
    }
    return 0;
}

全部评论

相关推荐

尊嘟假嘟点击就送:加v细说,问题很大
点赞 评论 收藏
分享
评论
点赞
收藏
分享
牛客网
牛客企业服务