URAL 1712. Cipher Grille (模拟)

16 篇文章 0 订阅

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.
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 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

inputoutput
....
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;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值