Secret Poems - HihoCoder - 1632

  图一                图二

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.InputThere 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.OutputFor each test case, convert the poem in old order into a poem in new order.

Sample Input

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

Sample Output

THISI
POEMS
DNKIA
OIHTV
OGYRE
AB
DC
ABEI
KHLF
NPOC
MJGD

大致题意:

  就是先按照图一的方式进行遍历这个图——按照图一的顺序存成一个字符串;然后按照图二的“回字形 ”顺序进行调整,然后输出图二!

AC题解:

  没错,题意就是这么简单!写的时候一不留神就出了很多BUG!然后改来改去花费了不少的时间!还是得细心点点!

  没有想到简单的办法,只好进行If...else...的嵌套!

 #include<stdio.h>
#include<math.h>
#include<string.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<set>
#include<vector>
#define inf 0x3f3f3f3f //Pangu and Stones ,I
#define ll long long
using namespace std;
#define N 108
char a[N][N];
char ans[N][N];
bool vis[N][N];
int dir[][]={ {,},{,},{,-},{-,},{,-},{-,} };
void factans(string s,int n){
int x=,y=;
memset(vis,false,sizeof(vis));
vis[][]=true;
memset(ans,'',sizeof(ans));
ans[][]=s[];
int op=-;
//先按之前的进行,右下左上右————
for(int i=;i<s.length();i++){
if(op!=-){
int dx=x+dir[op][];
int dy=y+dir[op][];
if(dx>=&&dx<=n-&&dy>=&&dy<=n-&&vis[dx][dy]==false){
x=dx;y=dy;
ans[x][y]=s[i];
vis[x][y]=true;
continue;
}
}
if(y+<=n-&&vis[x][y+]==false){//右下左上右————
ans[x][y+]=s[i];
y++;
op=;vis[x][y]=true;
}else if(x+<=n-&&vis[x+][y]==false){
ans[x+][y]=s[i];
x++;
op=;vis[x][y]=true;
}else if(y->=&&vis[x][y-]==false){
ans[x][y-]=s[i];
y--;
op=;vis[x][y]=true;
}else if(x->=&&vis[x-][y]==false){
ans[x-][y]=s[i];
x--;
op=;vis[x][y]=true;
}
}
for(int i=;i<n;i++)
ans[i][n]='\0';
for(int i=;i<n;i++)
printf("%s\n",ans[i]); }
int main(){
int n; while(scanf("%d",&n)!=EOF){
//int num=1;
for(int i=;i<n;i++)
scanf("%s",a[i]);
string s;
s.clear();
int i=,j=;
int op=-;
memset(vis,false,sizeof(vis));
while(){ s+=a[i][j];//存储当前位置 if(i==n-&&j==n-){
// cout<<"end: "<<s<<endl;
break;
} vis[i][j]=true; if(i==){//在第一行,可右0,可左下4,可下1
if(j+<=n-&&op!=){
i+=dir[][];
j+=dir[][];
op=;
}
else if(i+<=n-&&j->=&&vis[i+][j-]==false){
i+=dir[][];
j+=dir[][];
op=;
}
else{
i+=dir[][];
j+=dir[][];
op=;
}
}
else if(j==){//在第一列,先下1,后右上5,后右0
if(op!=&&i+<=n-){
i+=dir[][];
j+=dir[][];
op=;
}else if(i->=&&j+<=n-&&vis[i-][j+]==false){
i+=dir[][];
j+=dir[][];
op=;
}
else{
i+=dir[][];
j+=dir[][];
op=;
}
}
else if(i==n-){//最后一行,先右上5,后右0
if(i->=&&j+<=n-&&vis[i-][j+]==false){
i+=dir[][];
j+=dir[][];
op=;
}
else{
i+=dir[][];
j+=dir[][];
op=;
}
}
else if(j==n-){//最后一列,先左下4,后下1
if(i+<=n-&&j->=&&vis[i+][j-]==false){
i+=dir[][];
j+=dir[][];
op=;
}
else if(op!=){
i+=dir[][];
j+=dir[][];
op=;
}
}
else{//其余的照旧就可以了
i+=dir[op][];
j+=dir[op][];
}
}
factans(s,n); }
return ;
}

(有详细的解释呦!)

【恐怖的数组模拟】Secret Poems - HihoCoder - 1632的更多相关文章

  1. hihoCoder 1632 Secret Poems(ACM-ICPC北京赛区2017网络同步赛)

    时间限制:1000ms 单点时限:1000ms 内存限制:256MB 描述 The Yongzheng Emperor (13 December 1678 – 8 October 1735), was ...

  2. 2017 ICPC beijing F - Secret Poems

    #1632 : Secret Poems 时间限制:1000ms 单点时限:1000ms 内存限制:256MB 描述 The Yongzheng Emperor (13 December 1678 – ...

  3. 2017北京网络赛 F Secret Poems 蛇形回路输出

    #1632 : Secret Poems 时间限制:1000ms 单点时限:1000ms 内存限制:256MB 描述 The Yongzheng Emperor (13 December 1678 – ...

  4. 2018 Spring Single Training B (uva 572,HihoCoder 1632,POJ 2387,POJ 2236,UVA 10054,HDU 2141)

    这场比赛可以说是灰常的水了,涨信心场?? 今下午义务劳动,去拿着锄头发了将近一小时呆,发现自己实在是干不了什么,就跑到实验室打比赛了~ 之前的比赛补题补了这么久连一场完整的都没补完,结果这场比完后一小 ...

  5. uva 12100 Printer Queue 优先级队列模拟题 数组模拟队列

    题目很简单,给一个队列以及文件的位置,然后一个一个检查,如果第一个是优先级最高的就打印,否则放到队列后面,求所要打印的文件打印需要花费多长时间. 这里我用数组模拟队列实现,考虑到最糟糕的情况,必须把数 ...

  6. hdoj 2 括号配对问题【数组模拟实现+STL实现】

    栈遵循先进后出的原则 括号配对问题 时间限制:3000 ms  |  内存限制:65535 KB 难度:3   描述 现在,有一行括号序列,请你检查这行括号是否配对.   输入 第一行输入一个数N(0 ...

  7. 数据结构之【栈】+十进制转d进制(堆栈数组模拟)

    其实这篇文章开出来主要是水文章%% %% 栈--后进先出的婊 特点:只能在某一端插入和删除的特殊的线性表 操作:进栈--PUSH->向栈顶插入元素 出栈--POP-->将栈顶元素删除 实现 ...

  8. 简单用数组模拟顺序栈(c++版)适合新手

    **栈是一种操作受限制的线性表,太多官方的话我也不说了,我们都知道栈元素是先进后出的,它有两种存储结构,分别是顺序存储结构和链式存储结构. **今天我先记一下顺序存储结构,后面我会加上链式存储结构的. ...

  9. 简单用数组模拟顺序栈(c++)

    **栈是一种操作受限制的线性表,太多官方的话我也不说了,我们都知道栈元素是先进后出的,它有两种存储结构,分别是顺序存储结构和链式存储结构. **今天我先记一下顺序存储结构,后面我会加上链式存储结构的. ...

随机推荐

  1. 如何解决mac brew遇到无法下载的依赖?

    使用brew安装软件时,需要下载依赖包,但是如果依赖包特别大的时候,就很容易失败:brew本身不支持断点续传:但是可以使用wget -c的方式断点续传的下载依赖:下载完如何给brew安装使用呢?参考: ...

  2. iptables拦截tcp报文syn/ack/rst/psh/fin

    https://www.cnblogs.com/Qingluan/p/5137136.html https://blog.csdn.net/weixin_34216107/article/detail ...

  3. Python:实现图片裁剪的两种方式——Pillow和OpenCV

    原文:https://blog.csdn.net/hfutdog/article/details/82351549 在这篇文章里我们聊一下Python实现图片裁剪的两种方式,一种利用了Pillow,还 ...

  4. 【Chrome插件】Session Buddy--搁置标签页

    写在前面:看文章前请先看文章写作时间,避免浪费时间.2019-09-10 使用场景 Chrome打开许多网页,临时有事需要把当前的一些标签页一键保存,等待事后继续处理. 操作演示 原片地址:https ...

  5. context.xml文件配置

    <?xml version='1.0' encoding='utf-8'?> <Context> <WatchedResource>WEB-INF/web.xml& ...

  6. Word 域代码使用方法

    插入域「Crtl+F9」 更新域「F9」 切换域代码「Alt+F9」 批量删除域 打开 Word 文档,全选,按下「Alt+F9」键,将 Word 中所有的域结果切换为域代码的形式. 调出" ...

  7. Linux 安装部署 Redis

    一.Redis介绍 Redis是当前比较热门的NOSQL系统之一,它是一个key-value存储系统.和Memcache类似,但很大程度补偿了Memcache的不足,它支持存储的value类型相对更多 ...

  8. Linux基础-11-rpm管理软件包

    1. 使用RPM安装及移除软件 1) RPM的定义:RPM就是Red Hat Package Manger(红帽软件包管理工具)的缩写. 2) rpm的文件名分为5部分,其中: 第1部分是name,表 ...

  9. WUSTOJ 1335: Similar Word(Java)

    题目链接:1335: Similar Word Description It was a crummy day for Lur. He failed to pass to the CET-6 (Col ...

  10. hdu 6661 Acesrc and String Theory (后缀数组)

    大意: 求重复$k$次的子串个数 枚举重复长度$i$, 把整个串分为$n/i$块, 如果每块可以$O(1)$计算, 那么最终复杂度就为$O(nlogn)$ 有个结论是: 以$j$开头的子串重复次数最大 ...