题解 | #字符串加密#

字符串加密

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

#include <iostream>
using namespace std;
#include <bits/stdc++.h>
const string s = "abcdefghijklmnopqrstuvwxyz";
int main() {
    string key,str,table = "";
    cin>>key>>str;
    set<char>dic;
    for(char c : key){
        if(dic.count(tolower(c)) || dic.count(toupper(c))) continue;
        dic.insert(c);
        table += c;//保留key中大小写特征
    }
    for(int i = 0; i < 26; i++){
        if(dic.count(s[i]) || dic.count(toupper(s[i])) ) continue;
        table += s[i];
    }
    string res = "";
    for(int i = 0; i < str.size(); i++){
        if(str[i]>='A' && str[i]<='Z')res += table[str[i]-'A'];
        else res += table[str[i]-'a']; 
    }
    cout<<res<<endl;
    return 0;
}
// 64 位输出请用 printf("%lld")

全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务