import java.util.Scanner; // 注意类名必须为 Main, 不要有任何 package xxx 信息 public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); // 注意 hasNext 和 hasNextLine 的区别 while (in.hasNextLine()) { // 注意 while 处理多个 case String a = in.nextLine(); String b = in.nextLine(); System.out.println(encode(a)); System.out.println(decode(b)); } } private static String decode(String source) { StringBuilder builder = new StringBuilder(); for (int i = 0; i < source.length(); i++) { char c = source.charAt(i); if (Character.isLetter(c)) { builder.append(move(c, -1)); continue; } else if (Character.isDigit(c)) { int value = Integer.parseInt(source.substring(i, i + 1)); builder.append((value + 9) % 10); } else { builder.append(c); } } return builder.toString(); } private static String encode(String source) { /* 加密方法为: 当内容是英文字母时则用该英文字母的后一个字母替换,同时字母变换大小写,如字母a时则替换为B;字母Z时则替换为a; 当内容是数字时则把该数字加1,如0替换1,1替换2,9替换0; 其他字符不做变化。 */ StringBuilder builder = new StringBuilder(); for (int i = 0; i < source.length(); i++) { char c = source.charAt(i); if (Character.isLetter(c)) { builder.append(move(c, 1)); continue; } else if (Character.isDigit(c)) { int value = Integer.parseInt(source.substring(i, i + 1)); builder.append((value + 1) % 10); } else { builder.append(c); } } return builder.toString(); } private static Character move(Character c, int i) { //左移 if (i < 0) { Character cn = c; if (c == 'a' || c == 'A') { cn = 'Z'; } else { cn = (char) (c - 1); } return Character.isLowerCase(c) ? Character.toUpperCase( cn) : Character.toLowerCase(cn); } //右边移动 else { Character cn = c; if (c == 'z' || c == 'Z') { cn = 'a'; } else { cn = (char) (c + 1); } return Character.isLowerCase(c) ? Character.toUpperCase( cn) : Character.toLowerCase(cn); } } }