题解 | #字符串加解密#
字符串加解密
https://www.nowcoder.com/practice/2aa32b378a024755a3f251e75cbf233a
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); // 注意 hasNext 和 hasNextLine 的区别 while (in.hasNext()) { // 注意 while 处理多个 case String a = in.next(); String b = in.next(); System.out.println(ev(a, 1)); System.out.println(ev(b, -1)); } } //abcdefg //BCDEFGH private static String ev(String str, int offset) { int x = 0; int y = 0; char[] arr = str.toCharArray(); String r = ""; for (char s: arr) { if (s>=48 && s<=57) { int z = Integer.parseInt(s + ""); z += offset + 10; z = z % 10; s = (z+ "").charAt(0); } else if (s>=65&&s <=90) s = (char) (s + 32 + offset); else if(s>=97&&s<=122) { s = (char) (s - 32 + offset); } if (s == '@') s = 'Z'; if (s == '`') s = 'z'; if (s == '[') s = 'A'; if (s == '{') s = 'a'; r += s; } return r; } }