The Problem
Steganography is one of the most famous techniques for hiding information in different places, including images. Recently, for example, Xerox announced they were releasing a 2D-hieroglyphs that were able to codify a message within them. Your task is to decipher a 2D-hieroglyph.
A 2D hieroglyph is a matrix of 10 rows and columns that encode a message of length characters ( ). The matrix has the following lattice:
where
and is the ASCII value of the character passed to the function.
Your task is to find the message given the matrix .
The Input
The input is composed of a first line with a number indicating the number of messages to decode, followed by matrices separated by a "newline" character. The length of any message will not be more than 80 characters.
The Output
The output must have messages, one per each matrix given in the input.
Sample Input
2 /// //\///\/\\/\//\\/\//\/\\/\/\/\\/\/\//\/ ///\\/\/\//\//\\/\/ /\//\\\\///\\//\\/\\//\//\\//\///\/\\// /\//\\//\///\\\\//\//\\\\// //\\//\/\//\/\/\/\/ ///\//\//\///\//\///\// /\\/\\\\\\/\\/\\\\\\\/\\/\\\/\\\\\\\\\/ /// /// /// /\/\/\/\/\/ //\\//\\/// \\\\/// \\/ /// /\\\\\\\\\/ /\\\\\\\\\/ /// ///
Sample Output
LA LLUVIA EN SEVILLA ES UNA MARAVILLA abcdefghi
import java.io.FileInputStream;
import java.io.BufferedReader;
import java.io.BufferedInputStream;
import java.io.InputStreamReader;
import java.io.StreamTokenizer;
import java.io.PrintWriter;
import java.io.OutputStreamWriter;
import java.util.Scanner;
public class Main implements Runnable{
private static final boolean DEBUG = false;
private static final int ROW = 10;
private static final int[] exp = {1, 2, 4, 8, 16, 32, 64, 128};
private Scanner cin;
private PrintWriter cout;
private String[] s;
private void init()
{
try {
if (DEBUG) {
cin = new Scanner(new BufferedInputStream(
new FileInputStream("e:\\uva_in.txt")));
} else {
cin = new Scanner(new BufferedInputStream(System.in));
}
cout = new PrintWriter(new OutputStreamWriter(System.out));
} catch (Exception e) {
e.printStackTrace();
}
}
private void input()
{
s = new String[ROW];
for (int i = 0; i < ROW; i++) {
s[i] = cin.next();
}
}
private char check(int col)
{
for (int i = 0; i < 255; i++) {
boolean ok = true;
for (int j = 0; j < ROW - 2 && ok; j++) {
if (i / exp[j] % 2 == 1 && s[j + 1].charAt(col) == '/') ok = false;
else if (i /exp[j] % 2 == 0 && s[j + 1].charAt(col) == '\\') ok = false;
}
if (ok) return (char)i;
}
return (char)-1;
}
private void solve()
{
int M = s[0].length() - 2;
StringBuilder sb = new StringBuilder();
for (int i = 1; i <= M; i++) {
char ch = check(i);
if (ch != -1) sb.append(ch);
}
cout.println(sb.toString());
cout.flush();
}
public void run()
{
init();
int t = cin.nextInt();
while (t-- > 0) {
input();
solve();
}
}
public static void main(String[] args)
{
new Thread(new Main()).start();
}
}