To and Fro

Description

Mo and Larry have devised a way of encrypting messages. They first decide secretly on the number of columns and write the message (letters only) down the columns, padding with extra random letters so as to make a rectangular array of letters. For example, if the message is "There’s no place like home on a snowy night" and there are five columns, Mo would write down

t o i o y

h p k n n

e l e a i

r a h s g

e c o n h

s e m o t

n l e w x

Note that Mo includes only letters and writes them all in lower case. In this example, Mo used the character "x" to pad the message out to make a rectangle, although he could have used any letter.

Mo then sends the message to Larry by writing the letters in each row, alternating left-to-right and right-to-left. So, the above would be encrypted as

toioynnkpheleaigshareconhtomesnlewx

Your job is to recover for Larry the original message (along with any extra padding letters) from the encrypted one.

Input

There will be multiple input sets. Input for each set will consist of two lines. The first line will contain an integer in the range 2. . . 20 indicating the number of columns used. The next line is a string of up to 200 lower case letters. The last input set is followed by a line containing a single 0, indicating end of input.

Output

Each input set should generate one line of output, giving the original plaintext message, with no spaces.

Sample Input

5
toioynnkpheleaigshareconhtomesnlewx
3
ttyohhieneesiaabss
0

Sample Output

theresnoplacelikehomeonasnowynightx
thisistheeasyoneab 题目大意:

  给出2<=N<=20和加密过的字符串(长度<=200),输出解密后的字符串。

  加密规则:例如theresnoplacelikehomeonasnowynightx,按列写出,共N列

  t o i o y

  h p k n n
  e l e a i
  r a h s g
  e c o n h
  s e m o t
  n l e w x

  再按照奇数行,左至右,偶数行,右到左的顺序按行写出即可

代码如下:

 # include<stdio.h>
# include<string.h>
# define MAX
int n,m;
char s[MAX],ans[MAX][MAX];
int main(){
int i,j;
while(scanf("%d",&n) && n){
scanf("%s",s);
m = strlen(s)/n;
int cnt=;
for(i=; i<=m; i++){
if(i%)
for(j=; j<=n; j++)
ans[i][j] = s[cnt++];
else
for(j=n; j>=; j--)
ans[i][j] = s[cnt++];
}
for(i=; i<=n; i++)
for(j=; j<=m; j++)
printf("%c",ans[j][i]);
puts("");
}
return ;
}

POJ 2039 To and Fro(模拟)的更多相关文章

  1. POJ 2039 To and Fro

    To and Fro Description Mo and Larry have devised a way of encrypting messages. They first decide sec ...

  2. POJ 2039:To and Fro

    To and Fro Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 8632   Accepted: 5797 Descri ...

  3. poj 1008:Maya Calendar(模拟题,玛雅日历转换)

    Maya Calendar Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 64795   Accepted: 19978 D ...

  4. POJ 1027 The Same Game(模拟)

    题目链接 题意 : 一个10×15的格子,有三种颜色的球,颜色相同且在同一片内的球叫做cluster(具体解释就是,两个球颜色相同且一个球可以通过上下左右到达另一个球,则这两个球属于同一个cluste ...

  5. POJ 3414 Pots【bfs模拟倒水问题】

    链接: http://poj.org/problem?id=3414 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=22009#probl ...

  6. poj 2632 Crashing Robots(模拟)

    链接:poj 2632 题意:在n*m的房间有num个机器,它们的坐标和方向已知,现给定一些指令及机器k运行的次数, L代表机器方向向左旋转90°,R代表机器方向向右旋转90°,F表示前进,每次前进一 ...

  7. poj 1028 Web Navigation(模拟)

    题目链接:http://poj.org/problem? id=1028 Description Standard web browsers contain features to move back ...

  8. POJ 3087 Shuffle'm Up (模拟+map)

    题目链接:http://poj.org/problem?id=3087 题目大意:已知两堆牌s1和s2的初始状态, 其牌数均为c,按给定规则能将他们相互交叉组合成一堆牌s12,再将s12的最底下的c块 ...

  9. POJ 1068 Parencodings【水模拟--数括号】

    链接: http://poj.org/problem?id=1068 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=27454#probl ...

随机推荐

  1. JavaScript高级程序设计43.pdf

    事件类型 Web浏览器中有很多事件类型,“DOM3级事件”规定了以下几类事件 UI事件(用户界面),当用户与页面上的元素交互时触发: 焦点事件,当元素获得或失去焦点时触发 鼠标事件,当用户通过鼠标在页 ...

  2. Linux IIO子系统分析

    最近稍微看了下LKML,发现里面有一个子系统叫做“IIO”.以前没有接触过,所以Google了下.     IIO子系统全称是 Industrial I/O subsystem(工业 I/O 子系统) ...

  3. (DT系列一)DTS结构及其编译方法

    DTS结构及其编译方法 一:主要问题 1,需要了解dtsi与dts的关系 2,dts的结构模型 3,dts是如何被编译的,以及编译后会生成一个什么文件. 二:参考文字 1,DTS(device tre ...

  4. nginx配置文件的说明

    设置连接超时时间 http { ## # Basic Settings ## sendfile on; tcp_nopush on; tcp_nodelay on; keepalive_timeout ...

  5. hadoop2.2.0集群安装

    位说明. 位).Jdk使用的1.7(1.6也可以).网络配置好,相互可以ping通,java环境安装完毕.   第一部分 Hadoop 2.2 下载 位). 下载地址:http://apache.cl ...

  6. Jsp学习(2)

    Jsp的三大指令 (1).include 作用:相当于把当前页面去包含页面 语法: <%@include file="/common/test.jsp" %> 实例如下 ...

  7. Java - 推断元音辅音

    随机生成字母, 推断是元音字母还是辅音字母. [0,26) + 偏移量'a'就能够生成小写字母. 代码: //: Main.java import java.util.Random; /** * 推断 ...

  8. 【HDU 2014 Multi-University Training Contest 1 1002】/【HDU 4862】Jump

    多校训练就这么华丽丽的到了 ,于是乎各种华丽丽的被虐也開始了. 这是多校的1002; 最小费用最大流. 题目大意: 有n*m个方格,每一个方格都一个的十进制一位的数.你能够操作K次. 对于每一次操作, ...

  9. RAID 2.0

      传统的RAID 1.0: 选几个硬盘—>做成RAID 5—>根据容量创建LUN—>映射给主机 1.重建时间随单盘容量的增大而迅速增加 2.性能上,一个LUN的读写只能在一个磁盘组 ...

  10. lua wireshark 数据报解析

    http://www.360doc.com/content/13/1226/15/15257968_340284574.shtml http://www.360doc.com/userhome.asp ...