hihoCoder-1632模拟

题意:

描述

The Yongzheng Emperor (13 December 1678 – 8 October 1735), was the fifth emperor of the Qing dynasty of China. He was a very hard-working ruler. He cracked down on corruption and his reign was known for being despotic, efficient, and vigorous.

Yongzheng couldn’t tolerate people saying bad words about Qing or him. So he started a movement called “words prison”. “Words prison” means literary inquisition. In the famous Zhuang Tinglong Case, more than 70 people were executed in three years because of the publication of an unauthorized history of the Ming dynasty.

In short, people under Yongzheng’s reign should be very careful if they wanted to write something. So some poets wrote poems in a very odd way that only people in their friends circle could read. This kind of poems were called secret poems.

A secret poem is a N×N matrix of characters which looks like random and meaning nothing. But if you read the characters in a certain order, you will understand it. The order is shown in figure 1 below:

在这里插入图片描述

​ figure 1 figure 2

Following the order indicated by arrows, you can get “THISISAVERYGOODPOEMITHINK”, and that can mean something.

But after some time, poets found out that some Yongzheng’s secret agent called “Mr. blood dripping” could read this kind of poems too. That was dangerous. So they introduced a new order of writing poems as shown in figure 2. And they wanted to convert the old poems written in old order as figure1 into the ones in new order. Please help them.

输入

There are no more than 10 test cases.

For each test case:

The first line is an integer N( 1 <= N <= 100), indicating that a poem is a N×N matrix which consist of capital letters.

Then N lines follow, each line is an N letters string. These N lines represent a poem in old order.

输出

For each test case, convert the poem in old order into a poem in new order.

样例输入

5
THSAD 
IIVOP 
SEOOH 
RGETI 
YMINK
2
AB
CD
4
ABCD
EFGH
IJKL
MNOP

样例输出

THISI
POEMS
DNKIA
OIHTV
OGYRE
AB
DC
ABEI
KHLF
NPOC
MJGD

​ 翻译成汉语大概是将一串字符按图一的规律排列,让你输出将这串字符按图二的规律排列并输出。

思路:

​ 没啥别的,暴力大模拟就完了。。。不过暴力一定要优雅和简练!!比如我哈哈哈~

代码:

#include <stdio.h>
#include <inttypes.h>
#include <string.h>
#include <algorithm>
#define d int32_t
#define ll int64_t
#define r return
#define N 100000
#define For(i, star, endd) for(d i = star; i <= endd; i++)
#define Forr(i, star, endd) for(d i = star; i >= endd; i--)
#define mem(a) memset(a, 0, sizeof(a))
using namespace std;

char s1[105][105], s2[105][105], s3[105][105];

d main() {
    d n;
    while (scanf("%d", &n) == 1) {
        mem(s2);
        mem(s3);
        For(i, 0, n - 1) {
            scanf("%s", s1[i]);
        }
        int tot = 0;
        For(i, 0, 2 * n - 2) {
            if (i & 1) {
                For(j, 0, i) {
                    if (i - j > n - 1 || j > n - 1) continue;
                    s2[tot / n][tot % n] = s1[j][i - j];
                    tot++;
                }
            } else {
                Forr(j, i, 0) {
                    if (i - j > n - 1 || j > n - 1) continue;
                    s2[tot / n][tot % n] = s1[j][i - j];
                    tot++;
                }
            }
        }
        tot = 0;
        for (int i = n; i >= 1; i -= 2) {
            for (int j = (n - i) / 2; j <= n - 2 - (n - i) / 2; j++) {
                s3[(n - i) / 2][j] = s2[tot / n][tot % n];
                tot++;
            }
            for (int j = (n - i) / 2; j <= n - 2 - (n - i) / 2; j++) {
                s3[j][n - 1 - (n - i) / 2] = s2[tot / n][tot % n];
                tot++;
            }
            for (int j = n - 1 - (n - i) / 2; j >= (n - i) / 2 + 1; j--) {
                s3[n - 1 - (n - i) / 2][j] = s2[tot / n][tot % n];
                tot++;
            }
            for (int j = n - 1 - (n - i) / 2; j >= (n - i) / 2 + 1; j--) {
                s3[j][(n - i) / 2] = s2[tot / n][tot % n];
                tot++;
            }
        }
        if (n & 1) {
            s3[n / 2][n / 2] = s2[n - 1][n - 1];
        }
        For(i, 0, n - 1) {
            printf("%s\n", s3[i]);
        }
    }
    r 0;
}

转载请注明出处!!!

如果有写的不对或者不全面的地方 可通过主页的联系方式进行指正,谢谢

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值