To and Fro(1200)
来源:互联网 发布:centos强制删除文件夹 编辑:程序博客网 时间:2024/06/05 11:57
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.
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
5toioynnkpheleaigshareconhtomesnlewx3ttyohhieneesiaabss0
Sample Output
theresnoplacelikehomeonasnowynightxthisistheeasyoneab
#include <stdio.h>#include <string.h>#include <math.h>#include <stdlib.h>#include <ctype.h>int main(){char bu[401];char s[21][21];int count,i,j,l;int n;while(scanf("%d",&n)!=EOF){if(n==0)break;scanf("%s",bu);count=1;l=strlen(bu);for(i=0;i<l;i++){if(count%2==1){for(j=0;j<n;j++){s[count][j]=bu[i+j];}i=i+n-1;}else{for(j=n-1;j>=0;j--){s[count][j]=bu[i+n-1-j];}i=i+n-1;}count++;}/*for(i=1;i<count;i++){for(j=0;j<n;j++)printf("%c",s[i][j]);printf("\n");}*/for(i=0;i<n;i++){for(j=1;j<count;j++){printf("%c",s[j][i]);}}printf("\n");}return 0;}
0 0
- To and Fro(1200)
- 1200 To and Fro
- 1200 To and Fro
- hdu 1200 To and Fro
- hdu 1200 To and Fro
- hdu 1200 To and Fro
- HDU 1200 To and Fro
- hdu 1200 To and Fro
- hdoj 1200 To and Fro
- hdu-1200-To and Fro
- HDU-1200To and Fro
- hdu 1200 To and Fro
- hdu 1200 To and Fro
- HDU 1200 To and Fro
- hdu 1200 To and Fro
- hdoj 1200 To and Fro
- HDOJ 1200 To and Fro
- HDU 1200 To and Fro
- Error, some other host already uses address 22.22.22.2.
- Ant: for/foreach
- 从PLSQL从导出的CVS文件如何转化成XLS文件
- nagios监控dell服务器硬件
- Linux计划任务——cron服务
- To and Fro(1200)
- jquery stringify()方法
- php array_merge与数组+运算符
- velocity环境搭建
- 多线程(关于售票的简单应用)
- 二维凸包基本知识
- 【转载】J2SE知识点归纳笔记(六)---Java常用类
- 使用iOS 8 SDK添加Touch ID指纹识别功能
- Android5.0 Gallery2上编译Gallery模块出错