skip to main |
skip to sidebar
RSS Feeds
Nope. nothing .. just some random thoughts come to my mind ...
Nope. nothing .. just some random thoughts come to my mind ...
11:46 PM | Saturday, April 14, 2012
Posted by harshadura
Input |
3
|
Output |
Case #1: our language is impossible to understand |
/** * Google Code Jam - Qualification Round 2012 * Problem A. Speaking in Tongues * Author : harshadura@gmail.com * @harshadura */ import java.io.*; public class Main { private static String[] EncryptedLines; private static String[] DecryptedLines; public static void main(String[] args) { int i = 0; int j = 0; int count = 0; try { FileInputStream fstream = new FileInputStream("C:\\Users\\Harsha\\Documents\\NetBeansProjects\\GoogleCodeJamA\\A-small-attempt3.in"); DataInputStream in = new DataInputStream(fstream); BufferedReader br = new BufferedReader(new InputStreamReader(in)); String strLine; EncryptedLines = new String[100]; while ((strLine = br.readLine()) != null) { EncryptedLines[i++] = strLine; System.out.println(strLine); ++count; } in.close(); } catch (Exception e) { System.err.println("Error: " + e.getMessage()); } DecryptedLines = new String[count - 1]; int numTests = Integer.valueOf(EncryptedLines[0]); if (numTests < 1 || numTests > 30){ System.out.println("Invalid Input!!!!!!!!"); System.exit(0); } for (i = 1; i <= numTests; i++) { DecryptedLines[j++] = "Case #" + i + ": " + ConvertLine(EncryptedLines[i]); } String writableString = ""; for (int k = 0; k < DecryptedLines.length; k++) { if (k + 1 == DecryptedLines.length) { writableString = writableString + DecryptedLines[k]; break; } writableString = writableString + DecryptedLines[k] + "\n"; } writeToFile(writableString); } public static String ConvertLine(String plainText) { int size = plainText.length(); String decripted = ""; if (size > 100) { System.out.println("More than 100 Characters exceeded for a Single Case and Thats Invalid!!!!!!!!"); System.exit(0); } for (int i = 0; i < size; i++) { decripted = decripted + charMap(plainText.charAt(i)); } return decripted; } public static void writeToFile(String WrittenText) { try { BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); String file_name = "A-small-attempt3.out"; FileWriter fstream = new FileWriter(file_name); BufferedWriter out = new BufferedWriter(fstream); out.write(WrittenText); out.close(); System.out.println("File created successfully."); } catch (Exception e) { System.out.println(e.getMessage()); } } public static char charMap(char x) { switch (x) { case 'a': return 'y'; case 'b': return 'h'; case 'c': return 'e'; case 'd': return 's'; case 'e': return 'o'; case 'f': return 'c'; case 'g': return 'v'; case 'h': return 'x'; case 'i': return 'd'; case 'j': return 'u'; case 'k': return 'i'; case 'l': return 'g'; case 'm': return 'l'; case 'n': return 'b'; case 'o': return 'k'; case 'p': return 'r'; case 'q': return 'z'; case 'r': return 't'; case 's': return 'n'; case 't': return 'w'; case 'u': return 'j'; case 'v': return 'p'; case 'w': return 'f'; case 'x': return 'm'; case 'y': return 'a'; case 'z': return 'q'; } return x; } }
April 15, 2012 at 4:38 AM
Its given in the question bro. z -> q. The 'a zoo' hint
April 15, 2012 at 9:14 PM
yeah machan, but actually I didnt got the point while reading it. my bad! :/
April 16, 2012 at 1:28 AM
Thank you for your writeup, I've posted a functional solution here: http://bestinclass.dk/index.clj/2012/04/google-code-jam-1.html
April 16, 2012 at 6:51 AM
@Lau : thats awesome! simple, clean and very short code.. brilliant brain!
July 25, 2012 at 4:57 PM
WTF are you talking abt ?