题解 | #字符串加密#

字符串加密

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

#include <algorithm>
#include <any>
#include <iostream>
#include <string>
#include <vector>
using namespace std;

int charToint(char c)
{
    return c-'a';
}

int main() {
    string key;
    string s;
    cin >> key >> s;

    vector<char> res;
    for(char c : key)
    {
        if(count(res.begin(), res.end(), c) == 0)
        {
            res.push_back(c);
        }
    }
    for(char c = 'a'; c <= 'z'; c++)
    {
        if(count(res.begin(), res.end(), c) == 0)
        {
            res.push_back(c);
        }
    }

    string ans;
    for(char c : s)
    {
        ans.push_back(res[charToint(c)]);
    }

    cout << ans;
}
// 64 位输出请用 printf("%lld")

全部评论

相关推荐

鬼迹人途:你去投一投尚游游戏,服务器一面,第一个图算法,做完了给你一个策略题,你给出方案他就提出低概率问题,答不上当场给你挂
点赞 评论 收藏
分享
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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