hdu1200(模拟)
来源:互联网 发布:淘宝店铺买卖 编辑:程序博客网 时间:2024/06/05 11:14
To and Fro
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 6026 Accepted Submission(s): 4144
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.
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模拟题AC代码:#include<cstdio>#include<cstring>int main(){char str[300],ma[25][25];int n,m,i,j,k,x;while(scanf("%d",&n),n){getchar();scanf("%s",str);m=strlen(str);k=m/n;for(i=1,x=0;i<=k;i++){if(i&1){ for(j=1;j<=n;j++,x++) ma[i][j]=str[x];}else{ for(j=n;j>=1;j--,x++) ma[i][j]=str[x];}}for(i=1;i<=n;i++){for(j=1;j<=k;j++){if(ma[j][i]!=0) printf("%c",ma[j][i]);else printf("x");}}printf("\n");}return 0;}
0 0
- hdu1200(模拟)
- hdu1200
- HDU1200
- hdu1200(来来回回串起来)
- HDU1200:To and Fro
- HDU1200 To and Fro
- HDU1200 To and Fro
- hdu1200-二维数组问题
- HDU1200——字符串处理
- hdu1200使用stack和queue
- 杭电ACM—HDU1200
- HDU1200——To and Fro
- HDU1200-To and Fro(字符串)
- 模拟
- 模拟
- 模拟
- 模拟
- 模拟
- 2. PDO 的使用
- Android重力感应
- C++ 赋值运算符=重载
- [练习5]js学习之利用随机数滚动出现图片
- Android系统应用导入Eclipse中开发
- hdu1200(模拟)
- [经验]你想不到的PhpExcel导不出文件的原因
- linux shell 中的 2>&1 用法说明
- java 邮箱验证激活
- 报到博客_2016年4月4日
- 从上往下打印出二叉树的每个节点,同层节点从左至右打印。 java
- leetcode之two sum
- Cutting Game---博弈
- 【Android学习笔记】ListView使用SimpleAdapter适配器