Timus 1712. Cipher Grille 题解

Our program committee uses different tools for problem development: a mailing list, a version control system, an administration system of the Timus Online Judgewebsite, and many others. Chairman of the program committee must constantly keep the passwords for these systems in his head. Of course, the passwords must be kept secret from the contestants, otherwise the problems may become known to them before the contest starts.
Not trusting his memory, the chairman wants to write down one of the passwords in a ciphered form. To do this, he plans to use a cipher grille he read about in one entertaining book.
A cipher grille is a 4 × 4 paper square in which four windows are cut out. Putting the grille on a paper sheet of the same size, the chairman writes down the first four symbols of his password in the windows (see fig. below). After that the chairman turns the grille clockwise by 90 degrees. The symbols written earlier become hidden under the grille and clean paper appears in the windows. He writes down the next four symbols of the password in the windows and again turns the grille by 90 degrees. Then he writes down the following four symbols and turns the grille once more. After that he writes down the last four symbols of the password. Now, without the same cipher grille, it is very difficult to restore the password from the resulting square with 16 symbols. Thus, the chairman is sure that no contestant will get access to the problems too early.
Problem illustration
Assume that you obtained the grille used by the chairman and the resulting square with 16 symbols. Your task is to recover the chairman's password.

Input

The first four lines contain the chairman's cipher grille. The window in it is denoted by the symbol “X” and the paper is denoted by “.”. The position of this grille corresponds to the position from which the chairman starts writing down his password. It is guaranteed that the grille is correct, which means that in the process of ciphering only empty cells appear in the windows. It is also known that the grille is connected, i.e. it is a single piece of paper.
The next four lines contain the square with the ciphered password. All the symbols in the square are lowercase or uppercase Latin letters.

Output

Output the password of the chairman of the program committee as a string consisting of 16 symbols.

Sample

input output
....
X..X
.X..
...X
Pwoo
Khaa
smrs
odbk
KamkohobPassword


很有意思的一个加密题目。

加密方法:就是弄一个加密版,然后弄个纸 方块,这个纸方块中间开了特定的4个空,先贴在加密版上,写下4个字母,然后顺时针选择90度,再写下4个字母,继续选择2次,写下16个字母,就是最后的密码了。

现在写个解密算法。

考的知识点就是:旋转数组的问题。

#include <string>
#include <vector>
#include <iostream>
using namespace std;

static const int CI_NUM = 4;

void RotateCipher(vector<string> &cipherGrill)
{
	for (int i = 0; i < CI_NUM; i++)
	{
		for (int j = i, k = CI_NUM - i - 1; k > i; j++, k--)
		{
			char c = cipherGrill[i][j];
			cipherGrill[i][j] = cipherGrill[k][i];
			cipherGrill[k][i] = cipherGrill[CI_NUM-i-1][k];
			cipherGrill[CI_NUM-i-1][k] = cipherGrill[j][CI_NUM-i-1];
			cipherGrill[j][CI_NUM-i-1] = c;
		}
	}
}

void CipherGrille1712()
{
	vector<string> cipherGill(CI_NUM);
	vector<string> cipherBoard(CI_NUM);
	for (int i = 0; i < CI_NUM; i++)
	{
		cin>>cipherGill[i];
	}
	for (int i = 0; i < CI_NUM; i++)
	{
		cin>>cipherBoard[i];
	}
	string rs;
	for (int d = 0; d < CI_NUM; d++)
	{
		for (int i = 0; i < CI_NUM; i++)
		{
			for (int j = 0; j < CI_NUM; j++)
			{
				if ('X' == cipherGill[i][j]) rs.push_back(cipherBoard[i][j]);
			}
		}
		RotateCipher(cipherGill);
	}
	cout<<rs;
}

int main()
{
	CipherGrille1712();
	return 0;
}



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值