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. C# 匿名方法和拉姆达表达式

    有时候,我们需要封装一组数据,只有数据,没有方法,并且只用于当前程序,不需要在项目间重用,这时候,如果是传统的使用类来封装的话,大概会是下面这种样子: internal class SomeData ...

  2. ECMAScript6之数值类型的扩展

    数值类型的扩展 Number.isNaN ES6将isNaN方法从window身上移植到了Number对象上,使用时和ES5中的isNaN方法一样,但是这是Number对象的方法 Number.isN ...

  3. php计算几分钟前、几小时前、几天前的几个函数分享

    /* * 精确时间间隔函数 * $time 发布时间 如 1356973323 * $str 输出格式 如 Y-m-d H:i:s * 半年的秒数为15552000,1年为31104000,此处用半年 ...

  4. Objective-C Runtime 运行时之四:Method Swizzling(转载)

    理解Method Swizzling是学习runtime机制的一个很好的机会.在此不多做整理,仅翻译由Mattt Thompson发表于nshipster的Method Swizzling一文. Me ...

  5. TCP connect EADDRNOTAVAIL(99)错误原因分析

    转自:http://blog.chinaunix.net/uid-20662820-id-3371081.html 关于TCP connect 返回错误99,可以能大家都会遇到,这里就分析一下这个错误 ...

  6. Spark编程模型及RDD操作

    转载自:http://blog.csdn.net/liuwenbo0920/article/details/45243775 1. Spark中的基本概念 在Spark中,有下面的基本概念.Appli ...

  7. (转载)html中div使用自动高度

    为什么要使用div标签 1.更多的配置项,那就意味着更灵活,当然,难度也更高: 2.可以方便的容纳其他html标签:     static定位就是不定位,出现在哪里就显示在哪里,这是默认取值,只有在你 ...

  8. 安装器---Inno Setup

    Inno Setup[1]  用Delphi写成,其官方网站同时也提供源程序免费下载.它虽不能与Installshield这类恐龙级的安装制作软件相比,但也当之无愧算是后起之秀.Inno Setup是 ...

  9. Python笔记6(异常)-20160924

    1. NameError 当视图访问一个未定义的变量则会发生NameError.

  10. centos7内核升级

    默认centos7的内核版本是3.10,升级的原因是为了测试openvswitch的vlan技术,默认openvswitch的2.3版本是允许centos7默认内核3.10支持,下面是软件与内核版本对 ...