Main.java
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashMap;
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author cteam028
*/
public class Main {
public static final HashMap
<String, Character
> hm
= new HashMap
<String, Character
>(64); static{
cm[0] = "*-";
hm.put(cm[0], 'A');
cm[1] = "-***";
hm.put(cm[1], 'B');
cm[2] = "-*-*";
hm.put(cm[2], 'C');
cm[3] = "-**";
hm.put(cm[3], 'D');
cm[4] = "*";
hm.put(cm[4], 'E');
cm[5] = "**-*";
hm.put(cm[5], 'F');
cm[6] = "--*";
hm.put(cm[6], 'G');
cm[7] = "****";
hm.put(cm[7], 'H');
cm[8] = "**";
hm.put(cm[8], 'I');
cm[9] = "*---";
hm.put(cm[9], 'J');
cm[10] = "-*-";
hm.put(cm[10], 'K');
cm[11] = "*-**";
hm.put(cm[11], 'L');
cm[12] = "--";
hm.put(cm[12], 'M');
cm[13] = "-*";
hm.put(cm[13], 'N');
cm[14] = "---";
hm.put(cm[14], '0');
cm[15] = "*--*";
hm.put(cm[15], 'P');
cm[16] = "--*-";
hm.put(cm[16], 'Q');
cm[17] = "*-*";
hm.put(cm[17], 'R');
cm[18] = "***";
hm.put(cm[18], 'S');
cm[19] = "-";
hm.put(cm[19], 'T');
cm[20] = "**-";
hm.put(cm[20], 'U');
cm[21] = "***-";
hm.put(cm[21], 'V');
cm[22] = "*--";
hm.put(cm[22], 'W');
cm[23] = "-**-";
hm.put(cm[23], 'X');
cm[24] = "-*--";
hm.put(cm[24], 'Y');
cm[25] = "--**";
hm.put(cm[25], 'Z');
cm[26] = "**--";
hm.put(cm[26], '_');
cm[27] = "*-*-";
hm.put(cm[27], ',');
cm[28] = "---*";
hm.put(cm[28], '.');
cm[29] = "----";
hm.put(cm[29], '?');
}
/**
* @param args the command line arguments
*/
// TODO code application logic here
int[] arr = new int[1024];
while((line = br.readLine()) != null){
StringBuilder sb = new StringBuilder(4096);
int pos = 0;
for(char ch : line.toCharArray())
if(ch >= 'A' && ch <= 'Z')
{
sb.append(cm[ch - 'A']);
arr[pos++] = cm[ch - 'A'].length();
}
else
{
arr[pos++] = 4;
if(ch == '_')
sb.append(cm[26]);
else if(ch == ',')
sb.append(cm[27]);
else if(ch == '.')
sb.append(cm[28]);
else if(ch == '?')
sb.append(cm[29]);
}
pos--;
char[] nn = new char[line.length()];
int bot = 0;
for(int nnpos = 0; pos > -1; pos--, nnpos++)
{
// System.err.println("bot "+bot);
// System.err.println("len "+arr[pos]);
final String ak
= s.
substring(bot, bot
+ arr
[pos
]); nn[nnpos] = hm.get(ak);
bot += arr[pos];
}
}
}
}