To and Fro


Time Limit: 2 Seconds      Memory Limit: 65536 KB


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


题目的意思是给出每行字符个数和一个字符串,构造一个蛇形的矩阵,竖着输

根据题意按奇偶行构造矩阵并输出即可

#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 long
const int INF=0x3f3f3f3f; char a[1000];
char mp[1000][1000];
int main()
{
int n;
while(~scanf("%d",&n)&&n)
{
scanf("%s",a);
int k=strlen(a);
int cnt=0;
for(int i=0; i<k/n; i++)
{
if(i%2==0)
{
for(int j=0; j<n; j++)
mp[i][j]=a[cnt++];
}
else
{
for(int j=n-1; j>=0; j--)
mp[i][j]=a[cnt++];
}
}
for(int i=0; i<n; i++)
{
for(int j=0; j<k/n; j++)
{
printf("%c",mp[j][i]);
}
} printf("\n");
}
return 0;
}

ZOJ2208 To and Fro 2017-04-16 19:30 45人阅读 评论(0) 收藏的更多相关文章

  1. HDU6029 Happy Necklace 2017-05-07 19:11 45人阅读 评论(0) 收藏

    Happy Necklace                                                                           Time Limit: ...

  2. HDU6026 Deleting Edges 2017-05-07 19:30 38人阅读 评论(0) 收藏

    Deleting Edges                                                                                  Time ...

  3. 滑雪 分类: POJ 2015-07-23 19:48 9人阅读 评论(0) 收藏

    滑雪 Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 83276 Accepted: 31159 Description Mich ...

  4. HDU6027 Easy Summation 2017-05-07 19:02 23人阅读 评论(0) 收藏

    Easy Summation                                                             Time Limit: 2000/1000 MS ...

  5. The Pilots Brothers' refrigerator 分类: POJ 2015-06-15 19:34 12人阅读 评论(0) 收藏

    The Pilots Brothers' refrigerator Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 20304 ...

  6. IP Address 分类: POJ 2015-06-12 19:34 12人阅读 评论(0) 收藏

    IP Address Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 19125   Accepted: 11053 Desc ...

  7. ZOJ2256 Mincost 2017-04-16 19:36 44人阅读 评论(0) 收藏

    Mincost Time Limit: 2 Seconds      Memory Limit: 65536 KB The cost of taking a taxi in Hangzhou is n ...

  8. Making the Newsfeed web part available outside of My Sites in SharePoint 2013 分类: Sharepoint 2015-07-07 19:29 4人阅读 评论(0) 收藏

    The Newsfeed is a key piece in SP2013's approach to social computing. It appears on the landing page ...

  9. 利用YaHoo YUI实现Javascript CSS 压缩 分类: C# 2014-07-13 19:07 371人阅读 评论(0) 收藏

    网站优化时,往往需要对js文件,css文件进行压缩,以达到减少网络传输数据,减少网页加载时间:利用YaHoo的YUI可以实现Javascript,CSS,压缩,包括在线的js压缩和程序压缩,发现C#也 ...

随机推荐

  1. linux svn soeasy

    http://blog.163.com/longsu2010@yeah/blog/static/173612348201202114212933/

  2. api proxy设置 后端服务器代理

    location ^~ /api/{ ssi on; ssi_silent_errors off; proxy_redirect off; proxy_set_header Host $host; p ...

  3. C# 通过二进制,将多个文件合并为一个。

    C# 通过二进制,将多个文件合并为一个. /// <summary> /// 合并文件 /// </summary> /// <param name="strD ...

  4. Java 数组类型转字符串类型

    Java手册 String public String() 初始化一个新创建的 String 对象,使其表示一个空字符序列.注意,由于 String 是不可变的,所以无需使用此构造方法. String ...

  5. Windows 10 修改系统环境变量后,CMD生效,Powershell未生效

    Windows 10 修改系统环境变量后 1.CMD重新打开,新环境变量已经生效: 2.Shift+右键Powershell重新打开,新环境变量没有生效: 3.貌似服务(Apache24)中使用的环境 ...

  6. 蓝桥杯历届试题-垒色子(DP+矩阵快速幂)

    一.题目 垒骰子 赌圣atm晚年迷恋上了垒骰子,就是把骰子一个垒在另一个上边,不能歪歪扭扭,要垒成方柱体.经过长期观察,atm 发现了稳定骰子的奥秘:有些数字的面贴着会互相排斥!我们先来规范一下骰子: ...

  7. 第2章 Linux操作系统简介

    1. Linux操作系统的构成 (1)内核(kernel) ①操作系统的核心,负责管理系统的进程.内存.设备驱动程序.文件和网络系统. ②控制系统和硬件之间的相互通信. ③决定着系统的性能和稳定性. ...

  8. Building Your First App(创建你的第一个应用程序)

    欢迎来到Android应用开发 这部分课程将教你如何创建你的第一个android应用程序,包括如何创建一个android项目以并且在可调试模式下去运行这个应用程序, 您还将学习关于Android的应用 ...

  9. c#中var类型用法同dynamic,object区别

    1.object万能对象:object只是个对象,是个强类型,在编译的时候确定类型了,只能用对象本身的方法属性等等,object想使用动态属性方法只能用反射. 2.var万能强类型. 3.dynami ...

  10. lnmp架构实现动态php

    目录 LNMP动态网站php 1.PHP-FastCGI概述 PHP-FPM安装配置 配置PHP与数据库连接 配置PHP新增扩展模块 配置PHP-FPM主要配置 配置PHP-FPM错误日志 1.编译安 ...