UVA11716 Digital Fortress【解密】

In the last IIUPC there was a problem called Da Vinci Code prepared on the story of the bestselling book of Dan Brown, The Da Vinci Code. Here is another problem based on his another techno-thriller novel Digital Fortress. In this problem, you will be given a cipher text. Your task is to decipher the text using the decrypting technique described below. Let’s take an example. A cipher text is given as follows:
WECGEWHYAAIORTNU
        The output will be:
WEAREWATCHINGYOU
    For this problem, there are 16 characters in the given cipher text “WECGEWHYAAIORTNU” which is square of 4. These letters have to be arranged in n×n (in this example 4×4) grid and each letter from the given input will be placed in a grid in row major order (1st row, 2nd row, 3rd row, …). When the given cipher text is placed in the grid it looks like as follow:
W E C G
E W H Y
A A I O
R T N U
    From the above grid if we take the letters in column major order (1st column, 2nd column, 3rd column, …) then we get the following decrypted text:
WEAREWATCHINGYOU
Input
Input starts with a line consisting of a single number T. T test cases follow. Each test case consists of one line. This line contains the cipher text. The cipher text contains either UPPERCASE letters or blank spaces. Total number of character in the text will not be more 10,000.
Output
For each test case, the output contains a single line containing the decrypted text. If the number of characters in the input text is not square of any number, then give the output ‘INVALID’.
Sample Input
3
WECGEWHYAAIORTNU
DAVINCICODE
DTFRIAOEGLRSI TS
Sample Output
WEAREWATCHINGYOU
INVALID
DIGITAL FORTRESS

问题链接UVA11716 Digital Fortress
问题简述:(略)
问题分析
    。
    。
程序说明:(略)
参考链接:(略)
题记:(略)

AC的C++语言程序如下:

/* UVA11716 Digital Fortress */

#include <bits/stdc++.h>

using namespace std;

const int N = 10000;
char s[N + 1];

int main()
{
    int t;
    scanf("%d", &t);
    getchar();
    for(int k = 1; k <= t; k++) {
        gets(s);
        int len = strlen(s);
        int n = sqrt(len + 0.1);
        if(n * n != len)
            printf("INVALID\n");
        else {
            for(int i = 0; i < n; i++)
                for(int j = 0; j < n; j++)
                    putchar(s[j * n + i]);
            putchar('\n');
        }
    }

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值