题解 | #字符串加密#
字符串加密
http://www.nowcoder.com/practice/e4af1fe682b54459b2a211df91a91cf3
#include <string.h>
int main(void)
{
char str1[101] = {'\0'};
char str2[101] = {'\0'};
fgets(str1, 101, stdin);
fgets(str2, 101, stdin);
int len1 = (int) strlen(str1) - 1;
int len2 = (int) strlen(str2) - 1;
int k = 0;
int hash[26] = {'\0'};
char tmp[26] = {'\0'};
for (int i = 0; i < len1; ++i)
{
if (hash[str1[i] - 'a'] == 1)
continue;
hash[str1[i] - 'a'] = 1;
tmp[k] = str1[i];
k++;
}
for (int i = 0; i < 26; ++i)
{
if (hash[i] == 0)
{
tmp[k] = (char) (i + 'a');
k++;
}
}
for (int i = 0; i < len2; ++i)
{
str2[i] = tmp[str2[i] - 'a'];
}
printf("%s\n", str2);
return 0;
}