题解 | #字符串加密#

字符串加密

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

#include <stdio.h>
#include <string.h>

int main() {
    char str[108] = {0};
    char a_z[26] = {0};
    char keys[26] = {0};
    char ch = 0;
    int keyCount = 0;
    char words[108] = {0};
    while('\n' != (ch = getchar()))
    {
        if(0 == a_z[ch - 'a'])
        {
            keys[keyCount++] = ch;
            a_z[ch - 'a'] = 1;
        }
    }
    for(int i = 0; i < 26; i++)
    {
        if(0 == a_z[i])
        {
            keys[keyCount++] = i + 'a';
        }
    }
    scanf("%s",words);
    int wl = strlen(words);
    for(int i = 0; i < wl; i++)
    {
        printf("%c",keys[words[i] - 'a']);
    }


    return 0;
}

全部评论

相关推荐

点赞 评论 收藏
分享
评论
点赞
收藏
分享
牛客网
牛客企业服务