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. Ubuntu开发环境配置

    主要是: 源的更新 安装vim编辑器 远程登录xrdp相关配置 synergy symless键鼠共享配置 对新买的硬盘进行格式化和分区 vsftp环境搭建 gcc开发环境配置 qt5开发环境配置 m ...

  2. Collectd 和 InfluxDB 的部署和使用

    更新软件包 $ sudo apt-get update$ sudo apt-get upgrade$ sudo reboot 安装influxdb hanwei@ubuntu-lab:~$ wget ...

  3. shiro 的session持久化

    对于分布式系统,一般都牵扯到Session共享问题,而想实现Session共享,就要实现Session的持久化操作,即是将内存中的Session持久化至缓存数据库. SessionDAO是Shiro提 ...

  4. LeetCode 459. 重复的子字符串(Repeated Substring Pattern)

    459. 重复的子字符串 459. Repeated Substring Pattern 题目描述 给定一个非空的字符串,判断它是否可以由它的一个子串重复多次构成.给定的字符串只含有小写英文字母,并且 ...

  5. ABP中的本地化处理(下)

    在上篇文章中我们的重点是讲述怎样通过在Domain层通过PreInitialize()配置ILocalizationConfiguration中的Sources(IList<ILocalizat ...

  6. Android--单选对话框

    import android.app.AlertDialog; import android.content.Context; import android.content.DialogInterfa ...

  7. 使用babel es6 转 es5

    安装 //Webpack 接入 Babel 必须依赖的模块 npm i -D babel-core babel-loader //preset,告诉babel编译的文件中用到了哪些语法env包含当前所 ...

  8. 天梯赛 L2-024. 部落

    题解:并查集,这里要用路径压缩来优化 代码:// 这里范围理错了, 浪费20分钟debug #include <set> #include <iostream> #includ ...

  9. 翻译-在10行代码之内创建容器化的.net core应用

    本文翻译自Hans Kilian的文章 Creating a containerized .NET core application in less than 10 lines of code htt ...

  10. J.U.C之AQS:阻塞和唤醒线程

    此篇博客所有源码均来自JDK 1.8 在线程获取同步状态时如果获取失败,则加入CLH同步队列,通过通过自旋的方式不断获取同步状态,但是在自旋的过程中则需要判断当前线程是否需要阻塞,其主要方法在acqu ...