
I LOVE YOU HELLO WORLD 444 0 555 666 888 33 0 999 666 88 44 33 555 555 666 0 9 666 777 555 3
444 0 555 666 888 33 0 999 666 88 44 33 555 555 666 0 9 666 777 555 3 I LOVE YOU HELLO WORLD
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.Map;
public class Main{
private static Map<String,String> map=null;
public static void main(String[] args) throws Exception {
BufferedReader bf=new BufferedReader(new InputStreamReader(System.in));
Init();
while(true){
String str=bf.readLine();
if(str==null||str.equals(""))
break;
boolean ok=false;
for(int i=0;i<str.length();i++){
char c=str.charAt(i);
if(c>=‘A‘&&c<=‘Z‘&&c!=‘ ‘){
ok=true;
break;
}else if(c>=‘0‘&&c<=‘9‘&&c!=‘ ‘){
break;
}
}
if(ok){
System.out.print(map.get(str.charAt(0)+""));
for(int i=1;i<str.length();i++){
System.out.print(" "+map.get(str.charAt(i)+""));
}
System.out.println();
}
else{
String s[]=str.split(" ");
for(int i=0;i<s.length;i++){
if(s[i]!=null){
System.out.print(map.get(s[i]));
}
}
System.out.println();
}
}
}
private static void Init() {
map=new HashMap<String, String>();
map.put("A", "2");
map.put("B", "22");
map.put("C", "222");
map.put("D", "3");
map.put("E", "33");
map.put("F", "333");
map.put("G", "4");
map.put("H", "44");
map.put("I", "444");
map.put("J", "5");
map.put("K", "55");
map.put("L", "555");
map.put("M", "6");
map.put("N", "66");
map.put("O", "666");
map.put("P", "7");
map.put("Q", "77");
map.put("R", "777");
map.put("S", "7777");
map.put("T", "8");
map.put("U", "88");
map.put("V", "888");
map.put("W", "9");
map.put("X", "99");
map.put("Y", "999");
map.put("Z", "9999");
map.put(" ", "0");
map.put("2","A");
map.put("22","B");
map.put("222","C");
map.put("3","D" );
map.put("33","E");
map.put("333","F");
map.put("4","G");
map.put("44","H");
map.put("444","I");
map.put("5", "J");
map.put("55", "K");
map.put("555", "L");
map.put("6", "M");
map.put("66", "N");
map.put("666", "O");
map.put("7", "P");
map.put("77", "Q");
map.put("777", "R");
map.put("7777", "S");
map.put("8", "T");
map.put("88", "U");
map.put("888", "V");
map.put("9", "W");
map.put("99", "X");
map.put("999", "Y");
map.put("9999", "Z");
map.put("0", " ");
}
}
原文:http://blog.csdn.net/zhangyiacm/article/details/20551407