1712. Cipher Grille
Time limit: 0.5 second
Memory limit: 64 MB
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 conteststarts.
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.
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 positionof 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 |
Problem Author: Alex Samsonov (prepared by Alexander Ipatov)
Problem Source: NEERC 2009, Eastern subregional contest
解析:按题意模拟即可。
密码框每次向右转90°,每次读取密码框中的密码即可。
AC代码:
#include <bits/stdc++.h> using namespace std; char a[5][5], b[5][5], c; struct node{ int x, y; }; node d[5]; bool cmp(node a, node b){ if(a.x != b.x) return a.x < b.x; return a.y < b.y; } int main(){ #ifdef sxk freopen("in.txt", "r", stdin); #endif // sxk int cnt = 0; for(int i=1; i<=4; i++){ for(int j=1; j<=4; j++){ cin>>c; if(c == 'X') d[++cnt] = node{i, j}; } } for(int j=1; j<=4; j++) for(int k=1; k<=4; k++) cin>>a[j][k]; for(int i=1; i<=4; i++){ for(int j=1; j<=4; j++) cout<<a[d[j].x][d[j].y]; for(int j=1; j<=4; j++){ int x = d[j].x, y = d[j].y; d[j].x = y; d[j].y = 4 - x + 1; } sort(d+1, d+5, cmp); } puts(""); return 0; }