To and Fro
2015-07-21 20:40
288 查看
Time Limit : 2000/1000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other)
Total Submission(s) : 20 Accepted Submission(s) : 15Font: Times New Roman | Verdana | Georgia
Font Size: ← →
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 downt o i o yh p k n ne l e a ir a h s ge c o n hs e m o tn l e w xNote 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 astoioynnkpheleaigshareconhtomesnlewxYour 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(){int i,j,k,n,l;char x[1000];char s[1000][1000];while(scanf("%d",&n)&&n!=0){scanf("%s",x);j=strlen(x);k=j/n;for(l=0;l<k;l++)for(i=0;i<n;i++){if(l%2==0)s[l][i]=x[i+l*(n)];if(l%2!=0)s[l][i]=x[n-i-1+l*(n)];//printf("%c ",s[l][i]);}//printf("\n");for(i=0;i<n;i++){for(l=0;l<k;l++)printf("%c",s[l][i]);//printf("\n");}printf("\n");}return 0;}
相关文章推荐
- OC05 -- 数组
- 快速傅里叶变换(FFT)的C#实现及详细注释
- Record-2-4
- 今年暑假不AC
- 关于java基础--排序方法
- [CareerCup] 2.6 Linked List Cycle 单链表中的环
- PHPCMS \phpcms\modules\member\index.php 用户登陆SQL注入漏洞分析
- 逻辑回归模型分析
- 什么是线程,线程与进程有什么区别?
- CoreDataDemo
- swift2 自动引用计数
- 大图轮播
- Node.js的线程和进程
- [DLX重复覆盖] hdu 3957 Street Fighter
- POJ 1185 炮兵阵地(状态压缩dp)
- SQL server 2008数据库的备份与还原
- Spring Quartz集群(二)
- 为什么你只是个码农
- vs2012连接sql2008(错误类型:Could not load file or assembly)
- 判断链表 有环