题解 | #简单密码#
简单密码
https://www.nowcoder.com/practice/7960b5038a2142a18e27e4c733855dac
import java.util.HashMap;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
String s= in.next();
HashMap<Character,Integer> hm =new HashMap<>();
for (int i = 0; i < 3; i++) hm.put((char) ('a'+i),2);
for (int i = 0; i < 3; i++) hm.put((char) ('d'+i),3);
for (int i = 0; i < 3; i++) hm.put((char) ('g'+i),4);
for (int i = 0; i < 3; i++) hm.put((char) ('j'+i),5);
for (int i = 0; i < 3; i++) hm.put((char) ('m'+i),6);
for (int i = 0; i < 4; i++) hm.put((char) ('p'+i),7);
for (int i = 0; i < 3; i++) hm.put((char) ('t'+i),8);
for (int i = 0; i < 4; i++) hm.put((char) ('w'+i),9);
for (int i = 0; i < s.length(); i++)
if(s.charAt(i)>='a'&&s.charAt(i)<='z')
System.out.print(hm.get(s.charAt(i)));
else if(s.charAt(i)>='A'&&s.charAt(i)<='Z')
System.out.print((char)((Character.toLowerCase(s.charAt(i)) - 'a'+1)% 26 + 'a'));
else
System.out.print(s.charAt(i));
}
}
阿里云工作强度 703人发布
