题解 | #字符串加解密#

字符串加解密

https://www.nowcoder.com/practice/2aa32b378a024755a3f251e75cbf233a

import java.util.*;

// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        String L1 = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
        String L2 = "BCDEFGHIJKLMNOPQRSTUVWXYZAbcdefghijklmnopqrstuvwxyza1234567890";
        // 注意 hasNext 和 hasNextLine 的区别
        while (in.hasNext()) { // 注意 while 处理多个 case
            String a = in.nextLine();
            String b = in.nextLine();

            StringBuffer sb = new StringBuffer();
            for (int i = 0; i < a.length(); i++) {
                char t = L2.charAt(L1.indexOf(a.charAt(i)));
                sb.append(t);
            }
            System.out.println(sb.toString());
            sb.setLength(0);

            for (int i = 0; i < b.length(); i++) {
                char t = L1.charAt(L2.indexOf(b.charAt(i)));
                sb.append(t);
            }

            System.out.println(sb.toString());

        }
    }
}

全部评论

相关推荐

点赞 评论 收藏
转发
点赞 收藏 评论
分享
牛客网
牛客企业服务