ZOJ2208-To and Fro
来源:互联网 发布:西部世界解析 知乎 编辑:程序博客网 时间:2024/06/10 16:09
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.
SampleInput
5
toioynnkpheleaigshareconhtomesnlewx
3
ttyohhieneesiaabss
0
SampleOutput
theresnoplacelikehomeonasnowynightx
thisistheeasyoneab
Source: East Central North America 2004
题思:给出每行字符个数和一个字符串,构造一个蛇形的矩阵,竖着输
解题思路:根据题意按奇偶行构造矩阵
#include <iostream>#include <cstdio>#include <cstring>#include <string>#include <algorithm>#include <cmath>#include <map>#include <set>#include <stack>#include <queue>#include <vector>#include <bitset>using namespace std;#define LL long longconst int INF=0x3f3f3f3f;char ch[1000];char s[1000][1000];int main(){ int n; while(~scanf("%d",&n)&&n) { scanf("%s",ch); int len=strlen(ch); int cnt=0; for(int i=0; i<len/n; i++) { if(i%2==0) { for(int j=0; j<n; j++) s[i][j]=ch[cnt++]; } else { for(int j=n-1; j>=0; j--) s[i][j]=ch[cnt++]; } } for(int i=0; i<n; i++) { for(int j=0; j<len/n; j++) { printf("%c",s[j][i]); } } printf("\n"); } return 0;}
- zoj2208--------------------To and Fro
- ZOJ2208 To and Fro
- ZOJ2208-To and Fro
- zoj2208 To and Fro水题
- sicily1007. To and Fro
- 1007. To and Fro
- 1007. To and Fro
- 1007. To and Fro
- To and Fro
- To and Fro
- HDU1200:To and Fro
- 1007[To and Fro]
- To and Fro
- 1007. To and Fro
- sicily1007. To and Fro
- hdu_1200 To and Fro
- 1547. To and Fro
- HDU1200 To and Fro
- 仿智能指针
- 游戏制作要处理的相关细节
- 什么是P问题、NP问题和NPC问题
- 【Spring】使用Spring发送邮件
- AngularJS路由 $state服务、路由事件、获取路由参数
- ZOJ2208-To and Fro
- TextView 加边框
- 彻底理解python中函数内赋值操作和对象的可变性
- 树形DP
- Android之用命令uninstall卸载apk和用 -i 过滤日志忽略大小写
- 《JavaScript》*****src路径属性
- Easybet88 Online Casino Malaysia VIP Chip Redemption(Easybet88, Easybet88 Online, Sportbook, VIP Chi
- 洛谷P3369 普通平衡树(Treap/Splay)
- 选择排序算法