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:
![$\displaystyle H_{i,j} =\left\lbrace \begin{array}{ll}'/' & \forall i=0, j \in...... 2, \ldots , 8\right), j \in \left(1, 2, \ldots , M\right)\end{array} \right.$](http://uva.onlinejudge.org/external/108/p10851e.png)
where
![$\displaystyle b(i,c) =\left\lbrace \begin{array}{ll}'/' & \mathrm{if}\ \left(......m{if}\ \left( \frac{c}{2^i} \right) \mathrm{mod}\ 2 = 1\\\end{array} \right.$](http://uva.onlinejudge.org/external/108/p10851f.png)
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();
}
}