1547. To and Fro
来源:互联网 发布:数据分析师工资怎么样 编辑:程序博客网 时间:2024/06/06 18:39
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 yh p k n ne l e a ir a h s ge c o n hs e m o tn 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<iostream>#include<string>using namespace std;int main(){int n,ls,r,k,l;string s;char a[25][25];while(cin>>n&&n){cin>>s;ls=s.length();//cout<<ls<<endl;r=ls/n;//cout<<r<<endl;k=0;l=0;for(int i=0;i<r;i++){if(k==0){while(k<n){a[i][k]=s[l];//cout<<a[i][k]<<endl;l++;k++;}k--;//cout<<k<<endl;}else if(k==n-1){while(k>=0){a[i][k]=s[l];//cout<<a[i][k]<<endl;l++;k--;}k++;//cout<<k<<endl;}}for(int j=0;j<n;j++)for(int i=0;i<r;i++)cout<<a[i][j];cout<<endl;}return 0;}
- 1547. To and Fro
- TOJ 1547. To and Fro
- sicily1007. To and Fro
- 1007. To and Fro
- 1007. To and Fro
- zoj2208--------------------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
- HDU1200 To and Fro
- 1007. To and Fro
- 1200 To and Fro
- HTML 框架标记(1)——iframe(内嵌框架)
- android,音频频谱的绘制
- 手机视频监控解决方案(客户端)
- POJ 1125 Stockbroker Grapevine
- HDOJ 4893 Wow! Such Sequence!(线段树)
- 1547. To and Fro
- IOS-如何在UITableViewCell里进入ViewController
- APUE——进程关系
- Animation
- ios--文件创建,删除,判断某个文件是否存在
- 10分钟API Hook MessageBox
- HDU 1421 搬寝室——dp动态规划
- C++连接sql 2008 数据库
- Elastix 配合VOS使用说明(图文)