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. 《Netty实战》源码运行及本地环境搭建

     1.源码路径: GitHub - zzzvvvxxxd/netty-in-action-cn: Netty In Action 中文版 ,中文唯一正版<Netty实战>的代码清单 下载后 ...

  2. 窗口、消息查看分析利器Spy++

    Spy++ —— 窗口.消息查看分析利器 Spy++ —— 窗口.消息查看分析利器 2016年07月15日 00:25:22 阅读数:23170 1,简介   Microsoft Spy++是一个非常 ...

  3. 爬虫存储介质之MongoDB存储

    常用数据库 mongoDB4.0: 下载:https://www.mongodb.com/ windows安装.Linux安装见: https://www.runoob.com/mongodb/mon ...

  4. CentOS 安装tab命令补全

    CentOS 安装tab命令补全 1. 安装epel 源 yum -y install epel-release 2. 加快yum速度 yum -y install yum-plugin-fastes ...

  5. 6.2.3 reginst中的yzm

    @RequestMapping("/reginst/{yzm}") public Object reginst(User user,@PathVariable String yzm ...

  6. NGINX---一次阿里云宝塔开发flask经历

    1.放行端口问题 不但需要在阿里云官网服务器控制台放行端口,还需要在宝塔里面放行端口 2.nginx 宝塔默认的用户是www 句法: user user [group]; 默认: 用户无人; 语境: ...

  7. nohup 后台运行脚本,且可以实时查看日志

    -u加在python上 python命令加上-u(unbuffered)参数后会强制其标准输出也同标准错误一样不通过缓存直接打印到屏幕. 这是因为python的缓存机制所决定的 如果是使用 nohup ...

  8. 『Python基础』第20节:深浅copy

    一. 赋值运算 l1 = [1, 2, 'conan', [11, 22]] l2 = l1 l1[0] = 111 print(l1) # [111, 2, 'conan', [11, 22]] p ...

  9. JNI创建共享内存导致JVM terminated的问题解决(segfault,shared memory,内存越界,内存泄漏,共享内存)

    此问题研究了将近一个月,最终发现由于JNI不支持C中创建共享内存而导致虚拟机无法识别这块共享内存,造成内存冲突,最终虚拟机崩溃. 注意:JNI的C部分所使用的内存也是由JVM创建并管理的,所以C创建了 ...

  10. 怎样理解window对象的几组位置大小属性

    第一组: window.screenX 和 window.screenY, 只读, 返回浏览器窗口左上角与屏幕左上角的水平距离和垂直距离(单位像素); 第二组: window.innerHeight ...