题解 | #简单错误记录#
简单密码
http://www.nowcoder.com/practice/7960b5038a2142a18e27e4c733855dac
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.HashMap; import java.util.Map;
public class Main{
private static Map map = new HashMap<Character,Integer>(){{
put('1',1);
put('a',2);
put('b',2);
put('c',2);
put('d',3);
put('e',3);
put('f',3);
put('g',4);
put('h',4);
put('i',4);
put('j',5);
put('k',5);
put('l',5);
put('m',6);
put('n',6);
put('o',6);
put('p',7);
put('q',7);
put('r',7);
put('s',7);
put('t',8);
put('u',8);
put('v',8);
put('w',9);
put('x',9);
put('y',9);
put('z',9);
put('0',0);
}};
public static void main(String[] args){
InputStreamReader reader = new InputStreamReader(System.in);
StringBuffer sb= new StringBuffer();
String str ;
try(BufferedReader bf = new BufferedReader(reader)){
while((str = bf.readLine())!=null){
char[] chars= str.toCharArray();
for(int i = 0 ; i<chars.length ; i++){
if(48<=chars[i]&&chars[i]<=57) {
sb.append(chars[i]);
continue;
}
if (map.containsKey(chars[i])) {
sb.append(map.get(chars[i]));
continue;
}
chars[i] = (char)((chars[i] + 32 == 122)? 97 : chars[i]+33);
sb.append(chars[i]);
}
System.out.println(sb);
}
}catch(IOException e){
System.out.println(e.getMessage());
}
}
}