注册 登录  
 加关注
   显示下一条  |  关闭
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!立即重新绑定新浪微博》  |  关闭

告别迷茫

梦想与现实的差距,就是我们生活的意义。因为我们有差距,我们才会一直积累,在努力。

 
 
 

日志

 
 

HDU1200 To and Fro  

2014-03-31 14:00:51|  分类: HDU |  标签: |举报 |字号 订阅

  下载LOFTER 我的照片书  |


Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 4355    Accepted Submission(s): 3048


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
 

Source
 
基本意思就是解密的感觉啊
Recommend
Ignatius.L   |   We have carefully selected several similar problems for you:  1196 1073 1161 1020 1062 

#include<stdio.h>
#include<string.h>

char str[3000];
int main()
{
int i,j,n,m,len;
while(scanf("%d",&n)!=EOF)
{
getchar();
gets(str);
len=strlen(str);
m=len/n;
for(i=0;i<n;i++)
{
for(j=0;j<m;j++)
{
if(j%2==0)
printf("%c",str[j*n+i]);
if(j%2==1)
printf("%c",str[(j+1)*n-i-1]);//神奇的这个方式啊
}
}
printf("\n");

}

return 0;
}


  评论这张
 
阅读(12)| 评论(0)
推荐 转载

历史上的今天

在LOFTER的更多文章

评论

<#--最新日志,群博日志--> <#--推荐日志--> <#--引用记录--> <#--博主推荐--> <#--随机阅读--> <#--首页推荐--> <#--历史上的今天--> <#--被推荐日志--> <#--上一篇,下一篇--> <#-- 热度 --> <#-- 网易新闻广告 --> <#--右边模块结构--> <#--评论模块结构--> <#--引用模块结构--> <#--博主发起的投票-->
 
 
 
 
 
 
 
 
 
 
 
 
 
 

页脚

网易公司版权所有 ©1997-2017