| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
怎么会RE能,不懂啊,求高手帮忙,用的是java!import java.util.*;
class InitMap{
InitMap(HashMap map1,HashMap map2,HashMap map3){
map1.put("A", ".-");
map3.put(".-", "A");
map2.put("A", "2");
map1.put("B", "-...");
map3.put("-...", "B");
map2.put("B", "4");
map1.put("C", "-.-.");
map3.put("-.-.", "C");
map2.put("C", "4");
map1.put("D", "-..");
map3.put("-..", "D");
map2.put("D", "3");
map1.put("E", ".");
map3.put(".", "E");
map2.put("E", "1");
map1.put("F", "..-.");
map3.put("..-.", "F");
map2.put("F", "4");
map1.put("G", "--.");
map3.put("--.", "G");
map2.put("G", "3");
map1.put("H", "....");
map3.put("....", "H");
map2.put("H", "4");
map1.put("I", "..");
map3.put("..", "I");
map2.put("I", "2");
map1.put("J", ".---");
map3.put(".---", "J");
map2.put("J", "4");
map1.put("K", "-.-");
map3.put("-.-", "K");
map2.put("K", "3");
map1.put("L", ".-..");
map3.put(".-..", "L");
map2.put("L", "4");
map1.put("M", "--");
map3.put("--", "M");
map2.put("M", "2");
map1.put("N", "-.");
map3.put("-.", "N");
map2.put("N", "2");
map1.put("O", "---");
map3.put("---", "O");
map2.put("O", "3");
map1.put("P", ".--.");
map3.put(".--.", "P");
map2.put("P", "4");
map1.put("Q", "--.-");
map3.put("--.-", "Q");
map2.put("Q", "4");
map1.put("R", ".-.");
map3.put(".-.", "R");
map2.put("R", "3");
map1.put("S", "...");
map3.put("...", "S");
map2.put("S", "3");
map1.put("T", "-");
map3.put("-", "T");
map2.put("T", "1");
map1.put("U", "..-");
map3.put("..-", "U");
map2.put("U", "3");
map1.put("V", "...-");
map3.put("...-", "V");
map2.put("V", "4");
map1.put("W", ".--");
map3.put(".--", "W");
map2.put("W", "3");
map1.put("X", "-..-");
map3.put("-..-", "X");
map2.put("X", "4");
map1.put("Y", "-.--");
map3.put("-.--", "Y");
map2.put("Y", "4");
map1.put("Z", "--..");
map3.put("--..", "Z");
map2.put("Z", "4");
map1.put("_", "..--");
map3.put("..--", "_");
map2.put("_", "4");
map1.put(".", "---.");
map3.put("---.", ".");
map2.put(".", "4");
map1.put(",", ".-.-");
map3.put(".-.-", ",");
map2.put(",", "4");
map1.put("?", "----");
map3.put("----", "?");
map2.put("?", "4");
}
}
public class Main {
static String Reverse(String x){
int len=x.length();
StringBuffer y=new StringBuffer(x);
for (int i=0; i<len/2; i++){
char temp;
temp=y.charAt(i);
y.setCharAt(i, y.charAt(len-1-i));
y.setCharAt(len-1-i, temp);
}
return y.toString();
}
public static void main(String[] args) {
//初始化hashmap
HashMap map1=new HashMap();//存放Morse code
HashMap map2=new HashMap();//存放Morse code 的长
HashMap map3=new HashMap();
new InitMap(map1,map2,map3);
Scanner in=new Scanner(System.in);
int n=in.nextInt();
//in.nextLine();
for (int i=0; i<n; i++){
String code=in.next();
String temp1="";
String temp2="";
int len=code.length();
for (int j=0; j<len; j++){
//将code翻译成Morse code
char x=code.charAt(j);
temp1=temp1+map1.get(String.valueOf(x));
temp2=temp2+map2.get(String.valueOf(x));
}
//倒转temp2
temp2=Reverse(temp2);
//解释Morse code
code="";
int p=0;
//System.out.println(temp1+temp2);
for (int j=0; j<len; j++){
int index=temp2.charAt(j)-'0';
String temp3=temp1.substring(p, p+index);
p+=index;
code=code+map3.get(temp3);
}
System.out.println((i+1)+": "+code);
}
}
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator