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
#include<iostream>
#include<string>
using namespace std;
char a[][]; int main()
{
string str;
int column; while (cin >> column&&column != )
{
cin >> str; int row = str.length() / column ; for (int i = ; i < row; i++)
for (int j = ; j < column; j++)
a[i][j] = str[i*column + ((i % == ) ? (j) : (column - j - ))]; for (int i = ; i < column; i++)
for (int j = ; j < row; ++j)
cout << a[j][i]; cout << endl;
} 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 2039

    #include<iostream> #include<stdio.h> #include<string> #define MAXN 20 using namesp ...

  4. POJ 2039 Floyd

    句意理解题 解释输入好啦: 第一行n个数 m场电影 随后m行 每行的第一个数 代表 有k奶牛在这个电影中出现过 随后k个数 是奶牛的编号 如果两头奶牛在同一个电影中出现过 相互度为1 奶牛们的相互度可 ...

  5. poj 动态规划题目列表及总结

    此文转载别人,希望自己能够做完这些题目! 1.POJ动态规划题目列表 容易:1018, 1050, 1083, 1088, 1125, 1143, 1157, 1163, 1178, 1179, 11 ...

  6. poj动态规划列表

    [1]POJ 动态规划题目列表 容易: 1018, 1050, 1083, 1088, 1125, 1143, 1157, 1163, 1178, 1179, 1189, 1208, 1276, 13 ...

  7. POJ 动态规划题目列表

    ]POJ 动态规划题目列表 容易: 1018, 1050, 1083, 1088, 1125, 1143, 1157, 1163, 1178, 1179, 1189, 1208, 1276, 1322 ...

  8. poj 动态规划的主题列表和总结

    此文转载别人,希望自己可以做完这些题目. 1.POJ动态规划题目列表 easy:1018, 1050, 1083, 1088, 1125, 1143, 1157, 1163, 1178, 1179, ...

  9. [转] POJ DP问题

    列表一:经典题目题号:容易: 1018, 1050, 1083, 1088, 1125, 1143, 1157, 1163, 1178, 1179, 1189, 1191,1208, 1276, 13 ...

随机推荐

  1. [Q]AdobePDF打印机“仅依靠系统字体”问题

    使用Adobe打印机打印时提示: 解决方法: 不勾选“仅依靠系统字体”选项,并确认.

  2. 9.XML文件解析

    一.XML简介 XML(EXtensible Markup Language),可扩展标记语言 特点:XML与操作系统.编程语言的开发平台无关 实现不同系统之间的数据交换 作用:数据交互 配置应用程序 ...

  3. 带分页、过滤条件的DSL

    "query": { "bool": { "must_not": { "match_phrase": { "p ...

  4. 极路由器刷机安装ss插件最新教程

    极路由器系统升级后,旧的插件已不可用,这里是最新极路由器刷机教程,可实现绑定ss代理账号的功能. 获取root权限 安装开发者插件,获取root权限,请先登录极路由器后台(电脑浏览器访问 192.16 ...

  5. 在vmware workstation10上安装ubuntu14.04,出现以下问题

    VMware提示:已将该虚拟机配置为使用 64 位客户机操作系统.但是,无法执行 64 位操作. (1)设置bois 对于HP电脑来说,刚开机时,按住F10,会出现以下界面: 然后回车进行设置: 重启 ...

  6. CodeForces 709A Juicer

    简单题. #pragma comment(linker, "/STACK:1024000000,1024000000") #include<cstdio> #inclu ...

  7. 【JS】倒计时

    描述: 先要链接jquery.js,这样写法可以直接放JS文件运行. //放在图片里定位的倒计时 //顶图里面定位才使用的代码 document.writeln("<style> ...

  8. C# ExcelHelper

    using System; using System.IO; using System.Data; using System.Collections; using System.Data.OleDb; ...

  9. MAC OS 快捷键一览

    OS X 键盘快捷键 键盘快捷键是通过按下键盘上的组合键来调用 OS X 功能的一种方式.了解有关常见 OS X 键盘快捷键的信息. 若要使用键盘快捷键,您可以同时按修饰键和字符键.例如,按下 Com ...

  10. Struts2中实现文件上传的功能

    1.首先得配置一下Struts得配置文件struts-xml: <?xml version="1.0" encoding="UTF-8" ?> &l ...