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 ADMINISTR ation 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 is kept secret from the contestants, otherwise the problems could 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 does this, the 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 was cut out. Putting the grille on a paper sheet of the same size, the chairman writes down the first four symbols of he password in T He windows (see fig. below). After that, the chairman turns the grille clockwise by 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 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's very difficult to restore the password from the resulting square with the symbol S. Thus, the chairman is sure that no contestant would get access to the problems too early. Assume that's obtained the grille used by the Chairman and the resulting square with the symbols. Your task is to recover the chairman ' s password. Inputthe first four lines contain the Chairman ' s cipher Grille. The window in it was denoted by the symbol "X" and the paper was 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 this in the process of ciphering only empty cells appear in the W indows. It is also known the grille is connected, i.e. it's a single piece of paper. The next four lines contain the square with the ciphered password. All the SymBols in the square is lowercase or uppercase Latin letters. Outputoutput the password of the Chairman of the Program Committee as a string consisting of symbols. Sample
input |
Output |
.... X.. x.x ..... Xpwookhaasmrsodbk |
Kamkohobpassword |
problem Author:Alex Samsonov (prepared by Alexander Ipatov)
problem Source:NEERC, Eastern Subregional contest
Analysis: According to test instructions simulation can be.
Each time the password box is rotated 90° to the right, the password in the Password box is read each time.
AC Code:
#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;}
URAL 1712. Cipher Grille (Analog)