Problem 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 <stdio.h>
#include <string.h> int main()
{
char s[30][200],str[300];
int n,i,j,k,len;
while(~scanf("%d",&n),n)
{
scanf("%s",str);
len = strlen(str);
memset(s,'\0',sizeof(s));
k = 0;
for(i = 0;i<len/n && k<len;i++)
{
for(j = 0;j<n;j++)
{
if(i%2)
s[i][n-j-1] = str[k++];
else
s[i][j] = str[k++];
}
}
for(i = 0;i<n;i++)
{
for(j = 0;j<len/n;j++)
{
printf("%c",s[j][i]);
}
}
printf("\n");
}
return 0;
}

HDU1200:To and Fro的更多相关文章

  1. POJ 2039:To and Fro

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

  2. enmo_day_09

    1. 数据库 select name from v$database; : 数据库名称 select db_unique_name from v$database; : 数据库唯一名称 select ...

  3. 正则表达式 ——python 基础

    一.引言 正则表达式是含有文本和特别字符的字符串,这些文本和特别字符描述的模式可以识别各种字符串. 正则表达式的强大之处在于特殊符号的应用,特殊符号定义了字符集合.子组匹配,模式重复次数...正是这些 ...

  4. ORACLE_CLASS_ENDING

    [JSU]LJDragon's Oracle course notes In the first semester, junior year Oracle考前复习 试题结构分析: 1.选择题2x10, ...

  5. python 三元运算符、推导式、递归、匿名函数、内置函数

    三目运算符 # 三目(元)运算符:就是 if...else...语法糖 # 前提:简化if...else...结构,且两个分支有且只有一条语句 # 注:三元运算符的结果不一定要与条件直接性关系 cmd ...

  6. Python——day14 三目运算、推导式、递归、匿名、内置函数

    一.三目(元)运算符 定义:就是 if...else...语法糖前提:简化if...else...结构,且两个分支有且只有一条语句注:三元运算符的结果不一定要与条件直接性关系​ cmd = input ...

  7. day 14 递归、匿名函数、内置函数

    三目运算符 # 三目(元)运算符:就是 if...else...语法糖# 前提:简化if...else...结构,且两个分支有且只有一条语句# 注:三元运算符的结果不一定要与条件直接性关系​cmd = ...

  8. Python学习之路——三元运算符推导式

    三元运算符 # 生成器:包含yield关键字的函数就是生成器 def my_generator(): yield 1 yield 2 yield 3 g_obj = my_generator() # ...

  9. Day 14 三元运算符,列表推导式,内置函数

    三目运算符 ```python# 三目(元)运算符:就是 if...else...语法糖# 前提:简化if...else...结构,且两个分支有且只有一条语句# 注:三元运算符的结果不一定要与条件直接 ...

随机推荐

  1. GDB调试方法(转)

    一:列文件清单 1. List (gdb) list line1,line2 ************************************************************* ...

  2. Linux 分区初始化为物理卷,把物理卷加入卷组

    用到的命令有 1.pvcreate (physical volume create) 2.vgcreate (volume group create) 例子1:创建物理卷 pvcreate /dev/ ...

  3. NYOJ 7-街区最短路径问题(曼哈顿距离)

    街区最短路径问题 时间限制:3000 ms  |  内存限制:65535 KB 难度:4   描述 一个街区有很多住户,街区的街道只能为东西.南北两种方向. 住户只可以沿着街道行走. 各个街道之间的间 ...

  4. Android Intent的几种用法总结【转】

    Intent应该算是Android中特有的东西.你可以在Intent中指定程序要执行的动作(比如:view,edit,dial),以及程序执行到该动作时所需要的资料.都指定好后,只要调用startAc ...

  5. ORACLE 查找字段在哪些表里存在

    查找不是主键的字段在哪些表里存在: select owner, table_namefrom dba_tab_columnswhere lower(column_name)='firstname'; ...

  6. spm3 基本

    spm3 命令 spm init //初始化一个spm模块,会生成基本配置以及测试文件等(下图). //注 初始化以后一般需要 鲜执行一下 spm install 安装默认依赖模块 index.js就 ...

  7. iWeb峰会见闻

    8.16去参加了iWeb峰会,一大早8点过10分就到了,发现外面已经排起了长队(说明影响力越来越大,关注的人越来越多了.) 此次大会参与的企业也越来越多,当然是有目的而来~ 上午 google商业合作 ...

  8. BootStrap 模态框禁用空白处点击关闭问题

    模态框为信息编辑窗口,涉及好多内容,填了半天,若一不小心点了空白处,那就前功尽弃了..... 所以我们很有必要禁用鼠标点击空白处模态框关闭的功能. $('#myModal').modal({backd ...

  9. SQLSERVER 列名无效

    很多时候对数据库表修改字段后会出现“列名无效”,或者在查询分析器里面是红色的下划线,造成这个现象的原因是:SQL Server的intellisense(智能感知功能),没有感知到更改,需要重新整理一 ...

  10. kruskal算法求最小生成树(jungle roads的kruskal解法)

    注意: 注意数组越界问题(提交出现runtimeError代表数组越界) 刚开始提交的时候,边集中边的数目和点集中点的数目用的同一个宏定义,但是宏定义是按照点的最大数定义的,所以提交的时候出现了数组越 ...