UVa10851 - 2D Hieroglyphs decoder(枚举)

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 $ H$ of 10 rows and $ M+2$ columns that encode a message of length $ M$characters ( $ c_0, c_1, \ldots, c_{M-1}$). The matrix $ H$ 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.$

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.$

and $ c$ is the ASCII value of the character passed to the $ b$ function.

Your task is to find the message given the matrix $ H$.

The Input

The input is composed of a first line with a number $ N$ indicating the number of messages to decode, followed by $ N$ matrices separated by a "newline" character. The length of any message will not be more than 80 characters.

The Output

The output must have $ N$ 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();
	}
}



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
经导师精心指导并认可、获 98 分的毕业设计项目!【项目资源】:微信小程序。【项目说明】:聚焦计算机相关专业毕设及实战操练,可作课程设计与期末大作业,含全部源码,能直用于毕设,经严格调试,运行有保障!【项目服务】:有任何使用上的问题,欢迎随时与博主沟通,博主会及时解答。 经导师精心指导并认可、获 98 分的毕业设计项目!【项目资源】:微信小程序。【项目说明】:聚焦计算机相关专业毕设及实战操练,可作课程设计与期末大作业,含全部源码,能直用于毕设,经严格调试,运行有保障!【项目服务】:有任何使用上的问题,欢迎随时与博主沟通,博主会及时解答。 经导师精心指导并认可、获 98 分的毕业设计项目!【项目资源】:微信小程序。【项目说明】:聚焦计算机相关专业毕设及实战操练,可作课程设计与期末大作业,含全部源码,能直用于毕设,经严格调试,运行有保障!【项目服务】:有任何使用上的问题,欢迎随时与博主沟通,博主会及时解答。 经导师精心指导并认可、获 98 分的毕业设计项目!【项目资源】:微信小程序。【项目说明】:聚焦计算机相关专业毕设及实战操练,可作课程设计与期末大作业,含全部源码,能直用于毕设,经严格调试,运行有保障!【项目服务】:有任何使用上的问题,欢迎随时与博主沟通,博主会及时解答。
经导师精心指导并认可、获 98 分的毕业设计项目!【项目资源】:微信小程序。【项目说明】:聚焦计算机相关专业毕设及实战操练,可作课程设计与期末大作业,含全部源码,能直用于毕设,经严格调试,运行有保障!【项目服务】:有任何使用上的问题,欢迎随时与博主沟通,博主会及时解答。 经导师精心指导并认可、获 98 分的毕业设计项目!【项目资源】:微信小程序。【项目说明】:聚焦计算机相关专业毕设及实战操练,可作课程设计与期末大作业,含全部源码,能直用于毕设,经严格调试,运行有保障!【项目服务】:有任何使用上的问题,欢迎随时与博主沟通,博主会及时解答。 经导师精心指导并认可、获 98 分的毕业设计项目!【项目资源】:微信小程序。【项目说明】:聚焦计算机相关专业毕设及实战操练,可作课程设计与期末大作业,含全部源码,能直用于毕设,经严格调试,运行有保障!【项目服务】:有任何使用上的问题,欢迎随时与博主沟通,博主会及时解答。 经导师精心指导并认可、获 98 分的毕业设计项目!【项目资源】:微信小程序。【项目说明】:聚焦计算机相关专业毕设及实战操练,可作课程设计与期末大作业,含全部源码,能直用于毕设,经严格调试,运行有保障!【项目服务】:有任何使用上的问题,欢迎随时与博主沟通,博主会及时解答。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

kgduu

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值