题解 | #简单密码#
简单密码
http://www.nowcoder.com/practice/7960b5038a2142a18e27e4c733855dac
//JAVA 暴力解法 体力活
import java.util.*; //知识点在于把大写字符变成对应的小写字母且往后挪一位 //小写字母比大写字母ASCII码相差32,注意将大写字母'Z'单独进行处理 public class Main{ public static void main(String[] args){ Scanner scanner = new Scanner(System.in); while(scanner.hasNext()){ String pswStr =scanner.nextLine(); char[] ch = pswStr.toCharArray(); for(int i =0;i<pswStr.length();i++){ if(ch[i]>='a' && ch[i]<='c'){ System.out.print(2); }else if(ch[i]>='d' && ch[i]<='f'){ System.out.print(3); }else if(ch[i]>='g' && ch[i]<='i'){ System.out.print(4); }else if(ch[i]>='j' && ch[i]<='l'){ System.out.print(5); }else if(ch[i]>='m' && ch[i]<='o'){ System.out.print(6); }else if(ch[i]>='p' && ch[i]<='s'){ System.out.print(7); }else if(ch[i]>='t' && ch[i]<='v'){ System.out.print(8); }else if(ch[i]>='w' && ch[i]<='z'){ System.out.print(9); }else if(ch[i]>='A' && ch[i]<='Y'){ System.out.print((char)(ch[i]+33)); }else if(ch[i]=='Z'){ System.out.print('a'); }else if(ch[i]>='0' && ch[i]<='9'){ System.out.print(ch[i]); } } System.out.println(); } } }