URAL 1712. Cipher Grille (模拟)

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;
}
时间: 2024-10-06 16:33:38

URAL 1712. Cipher Grille (模拟)的相关文章

URAL 1654. Cipher Message (STL stack)

1654. Cipher Message Time limit: 1.0 second Memory limit: 64 MB Müller tried to catch Stierlitz red-handed many times, but alwaysfailed because Stierlitz could ever find some excuse. Once Stierlitz waslooking through his email messages. At that momen

URAL 1889. Airport Announcements 模拟题

1889. Airport Announcements Time limit: 1.0 second Memory limit: 64 MB Igor was bored of waiting in an airport lounge. Oceanic Airlines, a company he didn't like so much, delayed the departure of his flight, so he was late for the connection flight t

URAL 1893. A380(模拟啊 )

题目链接:http://acm.timus.ru/problem.aspx?space=1&num=1893 1893. A380 Time limit: 1.0 second Memory limit: 64 MB There was no limit to Jack's joy! He managed to buy on the Internet tickets to the ICPC semifinal contest, which was to be held very soon in

URAL 1996 Cipher Message 3

题目 神题. 记得当初DYF和HZA讲过一个FFT+KMP的题目,一直觉得很神,从来没去做. 没有真正理解FFT的卷积. 首先考虑暴力. 只考虑前7位 KMP 找出所有 B 串可以匹配 A 串的位置. 设 a(i) = A(i) & 1, b(i) = B(i) & 1 然后相当于求所有的 c(i) =  ∑k=0m-1 a(i+k) * b(k) 考虑卷积形式: c(i) =  ∑k=0m-1 a(k) * b(i - k) 将b串反过来 c(i) = ∑k=0m-1  a(k) * b

URAL 1711. Code Names (数学啊 )

题目链接:http://acm.timus.ru/problem.aspx?space=1&num=1711 1711. Code Names Time limit: 0.5 second Memory limit: 64 MB Imagine that you have to prepare a problem set for the forthcoming programming contest and you have already chosen the problems you wil

杭电ACM分类

杭电ACM分类: 1001 整数求和 水题1002 C语言实验题——两个数比较 水题1003 1.2.3.4.5... 简单题1004 渊子赛马 排序+贪心的方法归并1005 Hero In Maze 广度搜索1006 Redraiment猜想 数论:容斥定理1007 童年生活二三事 递推题1008 University 简单hash1009 目标柏林 简单模拟题1010 Rails 模拟题(堆栈)1011 Box of Bricks 简单题1012 IMMEDIATE DECODABILITY

【转】对于杭电OJ题目的分类

[好像博客园不能直接转载,所以我复制过来了..] 1001 整数求和 水题1002 C语言实验题——两个数比较 水题1003 1.2.3.4.5... 简单题1004 渊子赛马 排序+贪心的方法归并1005 Hero In Maze 广度搜索1006 Redraiment猜想 数论:容斥定理1007 童年生活二三事 递推题1008 University 简单hash1009 目标柏林 简单模拟题1010 Rails 模拟题(堆栈)1011 Box of Bricks 简单题1012 IMMEDI

转载:hdu 题目分类 (侵删)

转载:from http://blog.csdn.net/qq_28236309/article/details/47818349 基础题:1000.1001.1004.1005.1008.1012.1013.1014.1017.1019.1021.1028.1029. 1032.1037.1040.1048.1056.1058.1061.1070.1076.1089.1090.1091.1092.1093. 1094.1095.1096.1097.1098.1106.1108.1157.116

【模拟】ECNA 2015 I What&#39;s on the Grille? (Codeforces GYM 100825)

题目链接: http://codeforces.com/gym/100825 题目大意: 栅栏密码.给定N(N<=10),密钥为一个N*N的矩阵,'.'代表空格可以看到,'X'代表被遮挡,还有密文字符串S,长度为N*N 每次将这个矩阵顺时针旋转90°,把矩阵中空格对应的位置按照从上到下从左到右的顺序依次填充上密文字符,求最终这个密文字符能否填满N*N的矩阵,能按顺序输出得到的答案,不能输出"invalid grille" 题目思路: [模拟] 直接模拟即可.旋转的坐标公式很好推.