题解 | #字符串加密#
字符串加密
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; }