题解 | #字符串加密#

字符串加密

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

import java.util.*;

// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        
        String line1 = in.nextLine();
        String line2 = in.nextLine();
        Set<String> keySet = new LinkedHashSet();
        for(String s : line1.split("")) {
            keySet.add(s);
        }
        String key = String.join("",keySet);

        // System.out.println("key==:"+key);
        String az = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
        for(String s : az.split("")) {
            if(!key.toUpperCase().contains(s.toUpperCase())) {
                key += s;
            }

        }
        // key = key + az.substring(key.length());
        // System.out.println("key==:"+key);

        for(int i=0;i<line2.length();i++) {
            String s = line2.substring(i,i+1);
            if(!s.matches("[a-zA-Z]")) {
                System.out.println(s);
                continue;
            }
            int index = az.indexOf(s.toUpperCase());
            String replace = key.substring(index,index+1);
            replace = Character.isUpperCase(s.charAt(0)) ? replace.toUpperCase() : replace.toLowerCase();

            System.out.print(replace);

        }

    }
}

全部评论

相关推荐

菠落蜜:这个是系统自动投的,不是hr主动打招呼。更抽象的还有ai回复
我的秋招日记
点赞 评论 收藏
分享
迷茫的大四🐶:这才是秋招啊,我那除了广告还是广告的邮件通知,空白一片面试日程安排还配叫秋招吗
秋招白月光
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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