Created
May 23, 2013 21:45
-
-
Save bchetty/5639678 to your computer and use it in GitHub Desktop.
GCJ 2012 - Speaking In Tongues
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.HashMap; | |
/** | |
* | |
* @author Babji Prashanth, Chetty | |
*/ | |
public class GoogleRese { | |
public String translate(String input) { | |
HashMap<Character, Character> dict = getDictionary(); | |
StringBuilder sbTranslatedPhrase = new StringBuilder(); | |
for(int i=0;i<input.length();i++) { | |
char c = input.charAt(i); | |
sbTranslatedPhrase.append((c == ' ') ? ' ' : dict.get(c).charValue()); | |
} | |
return sbTranslatedPhrase.toString(); | |
} | |
private HashMap<Character, Character> getDictionary() { | |
HashMap<Character, Character> dict = new HashMap<Character, Character>(); | |
dict.put('a', 'y'); | |
dict.put('b', 'h'); | |
dict.put('c', 'e'); | |
dict.put('d', 's'); | |
dict.put('e', 'o'); | |
dict.put('f', 'c'); | |
dict.put('g', 'v'); | |
dict.put('h', 'x'); | |
dict.put('i', 'd'); | |
dict.put('j', 'u'); | |
dict.put('k', 'i'); | |
dict.put('l', 'g'); | |
dict.put('m', 'l'); | |
dict.put('n', 'b'); | |
dict.put('o', 'k'); | |
dict.put('p', 'r'); | |
dict.put('q', 'z'); | |
dict.put('r', 't'); | |
dict.put('s', 'n'); | |
dict.put('t', 'w'); | |
dict.put('u', 'j'); | |
dict.put('v', 'p'); | |
dict.put('w', 'f'); | |
dict.put('x', 'm'); | |
dict.put('y', 'a'); | |
dict.put('z', 'q'); | |
return dict; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment