题解 | #字符串加密#

字符串加密

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

import java.util.*;


public class Main {
    public static void main(String[] args) {
        Scanner fzhinput = new Scanner(System.in);
        String key = fzhinput.nextLine();
        List<String> xghzmb = new ArrayList<>();
        List<String> zmb = new ArrayList<>();
        int num;
        for(char c='a';c<='z';c++){
            zmb.add(Character.toString(c));
        }
        for(int i=0;i<key.length();i++){
            if(!xghzmb.contains(Character.toString(key.charAt(i)))){
                xghzmb.add(Character.toString(key.charAt(i)));
            }
        }
        for(char c='a';c<='z';c++){
            if(!xghzmb.contains(Character.toString(c))){
                xghzmb.add(Character.toString(c));
            }
        }
        String dclpassword = fzhinput.nextLine();
        for(int i=0;i<dclpassword.length();i++){
            char ch = dclpassword.charAt(i);
            num=0;
            for(String s: zmb){
                if(Character.toString(ch).equals(s)){
                    break;
                }
                num++;
            }
            System.out.print(xghzmb.get(num));

        }
    }
}

全部评论

相关推荐

10-28 14:42
门头沟学院 Java
watermelon1124:因为嵌入式炸了
点赞 评论 收藏
分享
评论
点赞
收藏
分享
牛客网
牛客企业服务