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<stdio.h>
#include<string.h>
using namespace std;
const int N=;
char str[N][N],na[N]; int main()
{
int n;
while(~scanf("%d",&n),n)
{
getchar();
gets(na);
int len=strlen(na);
int m=len/n;
int k=;
for(int i=;i<m;i++)
{
if(i%==)
{
for(int j=;j<n;j++)
{
str[i][j]=na[k];
k++;
}
}
else
{
for(int j=n-;j>=;j--)
{
str[i][j]=na[k];
k++;
}
}
}
for(int j=;j<n;j++)
{
for(int i=;i<m;i++)
{
printf("%c",str[i][j]);
} }
printf("\n");
}
return ;
}

To and Fro的更多相关文章

  1. hdoj 1200 To and Fro

    To and Fro Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total ...

  2. POJ 2039 To and Fro(模拟)

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

  3. To and Fro(字符串水题)

    To and Fro 点我 Problem Description Mo and Larry have devised a way of encrypting messages. They first ...

  4. POJ 2039 To and Fro

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

  5. ZOJ2208 To and Fro 2017-04-16 19:30 45人阅读 评论(0) 收藏

    To and Fro Time Limit: 2 Seconds      Memory Limit: 65536 KB Mo and Larry have devised a way of encr ...

  6. hdu 1200 To and Fro(简单模拟或DP)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1200 To and Fro Time Limit: 2000/1000 MS (Java/Others ...

  7. 解决Turn your Session into FlushMode.COMMIT/AUTO or remove 'readOnly' marker fro问题

    项目中碰到一个问题,就是将一个map转换成json格式的时候出现错误,最后排查将延迟加载关闭后成功转换,因为数据量较大,于是重新创建了一个对象进行接收. 解决办法是在配置文件中进行配置 虽然解决了这个 ...

  8. hdu_hpu第八次周赛_1001 To and Fro 201310270918

    To and Fro Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 65536/32768K (Java/Other) Total Su ...

  9. POJ 2039:To and Fro

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

  10. sicily 1007. To and Fro 2016 11 02

    // Problem#: 1007// Submission#: 4893204// The source code is licensed under Creative Commons Attrib ...

随机推荐

  1. 张艾迪Eidyzhang:解码天才Eidyzhang的诞生

    AOA解码:天才Eidyzhang的诞生AOA深度解读:世界第一天才Eidyzhang: (TheWorldNo.1Girl+TheWorldNo.1InterentGirl+世界第一女孩+世界第一互 ...

  2. JavaScript中的test()方法

    定义和用法 test() 方法用于检测一个字符串是否匹配某个模式. 语法 RegExpObject.test(string) 参数 描述 string 必需.要检测的字符串. 返回值 如果字符串 st ...

  3. linux命令备份

    sort -t $'\t' gcc版本查看 gcc -v 红帽版本查看 cat /etc/redhat-release Linux Core Version  cat /proc/version

  4. BZOJ1570 [JSOI2008]Blue Mary的旅行

    建分层图,每一层表示一天的情况 从S向第0层的1号点连边,每层的n向T连INF的边 枚举天数,每多一天就多建一层然后跑最大流,如果当前流量大于人数则输出答案 由于路径长度不会超过n,因此tot个人走这 ...

  5. Hyper-V和Virtual PC的不同

    微软在2003年收购了推出了Virtual PC软件的Connectix公司,并在其后推出了Virtual Server服务器虚拟化软件 Hyper-V跟微软自家的Virtual PC.Virtual ...

  6. Codeigniter 集成sphinx搜索 这里采用的是coreseek中文搜索引擎,具体安装请参考官方网站

    先上效果图 加入sphinx类库(/application/libraries/sphinx_client.php) 0001 <?php 0002 0003 // 0004 // $Id: s ...

  7. POJ 1422 二分图(最小路径覆盖)

    Air Raid Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 7278   Accepted: 4318 Descript ...

  8. Topcoder SRM 584 DIV1 600

    思路太繁琐了 ,实在不想解释了 代码: #include<iostream> #include<cstdio> #include<string> #include& ...

  9. 用PDB库调试Python程序

    Python自带的pdb库,发现用pdb来调试程序还是很方便的,当然了,什么远程调试,多线程之类,pdb是搞不定的. 用pdb调试有多种方式可选: 1. 命令行启动目标程序,加上-m参数,这样调用my ...

  10. MATLAB 函数

    MATLAB函数大全 1.常见 http://wenku.baidu.com/link?url=tPpwD7Ox_1sG-SQv_XdYszBAPY9LX_Zb_dde_5JeOiu7RwN_i14X ...