题解 | #简单密码#
简单密码
http://www.nowcoder.com/practice/7960b5038a2142a18e27e4c733855dac
Java
public class Main{
public static void main(String[] args){
Scanner in = new Scanner(System.in);
String str = in.nextLine();
StringBuilder sb = new StringBuilder();
int len = str.length();
for(int i = 0; i < len; i++){
char ch = str.charAt(i);
if(ch >= 'A' && ch <= 'Z'){
int t = (int)(ch - 'A');
int index = ((int)(ch - 'A') + 1) % 26;
char ch2 = (char)(index + (int)'a');
sb.append(ch2);
}else if(ch >= 'a' && ch <= 'o'){
int num = (((int)(ch - 'a')) / 3) + 2;
sb.append(num);
}else if(ch >= 'p' && ch <= 's'){
sb.append(7);
}else if(ch >= 't' && ch <= 'v'){
sb.append(8);
}else if(ch >= 'w' && ch <= 'z'){
sb.append(9);
}else{
sb.append(ch);
}
}
System.out.print(sb);
}
}