zoukankan      html  css  js  c++  java
  • Timus 1712. Cipher Grille 题解

    版权声明:本文作者靖心,靖空间地址:http://blog.csdn.net/kenden23/。未经本作者同意不得转载。 https://blog.csdn.net/kenden23/article/details/24574109

    Our program committee uses different tools for problem development: a mailing list, a version control system, an administration system of the Timus Online Judge website, 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;
    }



  • 相关阅读:
    Solr使用初探——SolrJ的使用
    Solr使用初探——Solr的安装环境与配置
    solr教程,值得刚接触搜索开发人员一看
    2013已过去,迎来2014,我们该如何规划自己的生活及职业生涯
    搭建集群必备:windows如何使用Xshell远程连接(SSH)Linux
    集群搭建:主机宽带拨号上网,虚拟机使用桥接模式,该如何ping通外网
    什么是Zookeeper,Zookeeper的作用是什么,在Hadoop及hbase中具体作用是什么
    如何搭建云平台,云平台搭建,需要学习什么云技术
    hadoop入门必备基础知识
    如何进行Hadoop二次开发指导视频下载
  • 原文地址:https://www.cnblogs.com/ldxsuanfa/p/10881855.html
Copyright © 2011-2022 走看看