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高级程序设计36.pdf

    TreeWalker TreeWalker是NodeIterator的更高级的版本,除了包括nextNode()和previousNode()在内的相同功能外,这个类型还提供了用于不同方向上遍历DOM ...

  2. msm8610 lcd driver code analysis

    ---恢复内容开始--- 1  lcd probe The probe sequence is determined by compilation sequence: mdss-mdp3-objs = ...

  3. openstack kvm 虚拟机磁盘差异衍生

    1, openstack虚拟实例备份之--多镜像格式多镜像文件合并为一个镜像文件衍生-差异镜像文件    /var/lib/nova/instances/b0abc22f-1a73-4079-b1bc ...

  4. Codeblocks + opencv + Cmake + minGW 环境搭建(一劳永逸版)

    应工作开发需要,今天搭建一个codeblocks的C++开发环境,需要配置opencv2.4.4的API协同开发. 1.为了避免不必要的配置编译器,下载codeblocks16.1带mingw编译器版 ...

  5. Linq中Take、TakeWhile、Skip、SkipWhile的比较(转)

    参考文章:http://blog.csdn.net/lxfzgg/article/details/20534281 Take() , , , , , , , , , }; ); //从第一个元素开始, ...

  6. tomcat多域名配置

    1.找到你的tomcat然后在conf文件中找到server.xml打开: <Server port="8005" shutdown="SHUTDOWN" ...

  7. [一位菜鸟的COCOS-2D编程之路]COCOS2D中得动作,特效和动画

    一,CCActionManager 管理所有节点动作的对象 来看看打飞机里面的一个onEnter 方法 - (void)onEnter { [super onEnter]; //一定要注意添加此方法, ...

  8. Ajax 整理总结(进阶)

    Ajax 进阶学习要点:1.加载请求2.错误处理3.请求全局事件4.JSON 和 JSONP5.jqXHR 对象 一.加载请求 在 Ajax 异步发送请求时,遇到网速较慢的情况,就会出现请求时间较长的 ...

  9. ARCproject中加入非ARC文件,或者非ARC环境中加入ARC文件

    ARC与非ARC在一个项目中同一时候使用, 选择项目中的Targets,选中你所要操作的Target,选Build Phases,在当中Complie Sources中选择须要ARC的文件双击,并在输 ...

  10. GDB的non-stop模式

    线程调试必杀技 - GDB的non-stop模式   作者:破砂锅 开源的GDB被广泛使用在Linux.OSX.Unix和各种嵌入式系统(例如手机),这次它又带给我们一个惊喜. 多线程调试之痛 调试器 ...