hdu 1200 To and Fro
来源:互联网 发布:美国网络中立 编辑:程序博客网 时间:2024/05/20 04:14
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.
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>int main(){ int n,f; char str[220]; char res[25][25]; int i,j,k,len,x; while(scanf("%d",&n)&&n) { memset(str,0,sizeof(str)); memset(res,0,sizeof(res)); scanf("%s",str); len = strlen(str); x = 0; for(i=1;i<=len/n;i++) { if(i&1) { for(j=0;j<n;j++) { res[i][j] = str[x++]; } //printf("%s\n",res[i]); } else { for(j=n-1;j>=0;j--) { res[i][j] = str[x++]; } //printf("%s\n",res[i]); } } for(j=0;j<n;j++) { for(i=1;i<=len/n;i++) printf("%c",res[i][j]); } printf("\n"); } return 0;}---------------------------------------------------------------------------------------------------------
0 0
- 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
- 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
- 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
- hdu-1200 To and Fro
- HDU 1200 To and Fro
- android 内存溢出问题分析
- HDU-2089 不要62
- 优秀有价值的博客收藏列表(持续更新)
- 卷积特征提取与池化(Pooling)——处理大型图像
- php + mysql 分布式事务(xa)
- hdu 1200 To and Fro
- JAVA:Stack栈和Heap堆的区别
- NYOJ44,子串和
- 二叉树中相距最远的两个节点之间的距离
- JNI学习积累之一 ---- 常用函数大全
- 阿斯达四大四大
- python对象与json
- java使用android aapt获取APK信息
- 归并排序