【十二题解】 | #字符串加密#

字符串加密

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

#include<stdio.h>

int main(){

char data[100];
while(scanf("%s", data) != EOF){
    char val[100];
scanf("%s", val);
char key[26]={0};
char hash[26]={0};
int loc =0;
for(int i=0; data[i] != '\0'; i++){
    if(hash[data[i]-'a']==0){
        hash[data[i]-'a']=1;
        key[loc]=data[i];
        loc++;
    }
}
for(int i=0; i<26; i++){
    if(hash[i] == 0){
        key[loc] = i+'a';
        loc++;
        hash[i]=1;
    }
}
for(int i=0; val[i] != '\0'; i++){
    printf("%c", key[val[i]-'a']);
}
    printf("\n");
}

}

全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

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