题解 | #简单密码#
简单密码
http://www.nowcoder.com/practice/7960b5038a2142a18e27e4c733855dac
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner input=new Scanner(System.in); String string=input.nextLine(); for (int i = 0; i < string.length(); i++) { String s=string.substring(i,i+1); //小写 if (s.matches("[a-z]")) { if (s.matches("[a-c]")) { System.out.print(2); } if (s.matches("[d-f]")) { System.out.print(3); } if (s.matches("[g-i]")) { System.out.print(4); } if (s.matches("[j-l]")) { System.out.print(5); } if (s.matches("[m-o]")) { System.out.print(6); } if (s.matches("[p-s]")) { System.out.print(7); } if (s.matches("[t-v]")) { System.out.print(8); } if (s.matches("[w-z]")) { System.out.print(9); } } //数字 if (s.matches("[0-9]")) { System.out.print(s); } //大写 if (s.matches("[A-Y]")) { System.out.print((char)(s.charAt(0)+33)); } if (s.matches("[Z]")) { System.out.print("a"); } } } }