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. python 书籍推荐 二

    Python是一中面向对象的编程语言,语法简洁而清晰,具有丰富和强大的类库.对于初学编程者来说,首选Python是个非常棒的选择.   工具/原料 Python Python学习前的准备 1 学习任何 ...

  2. Java toString()方法的神奇之处

    Java 手册 toString(String类中) public String toString() 返回此对象本身(它已经是一个字符串!). 指定者: 接口 CharSequence 中的 toS ...

  3. T-SQL 总结

    SP0_AddLinkedServer.sql [创建Linked SQL Server ] USE [master] GO ) drop procedure dbo.SP_Temp_AddLinke ...

  4. 6_bootstrap之导航条|轮播图|排版|表单元素|分页

    8.导航条 BootStrap已经提供了完整的导航条实例,通常情况下,我们仅需进行简单修改即可使用. 帮助手册位置:组件-------导航条 9.轮播图 BootStrap已经提供了完整的轮播图实例, ...

  5. ScheduledThreadPoolExecutor 线程池调度 使用

    package other; import java.util.concurrent.Callable; import java.util.concurrent.Executors; import j ...

  6. sql日期查询

    select getdate() ,getdate()) ,getdate()) ) ,getdate())) ,getdate())) Select datename(weekday, getdat ...

  7. archlinux错误:无法提交处理 (无效或已损坏的软件包)

    1.首先更新一下密钥,如果没有安装archlinux-keyring,请及时安装 sudo pacman-key --refresh-keys 2.重新加载相应的签名密钥 sudo pacman-ke ...

  8. Redis AOF文件

    [Redis AOF文件] 1.关于AOF AOF 持久化记录服务器执行的所有写操作命令,并在服务器启动时,通过重新执行这些命令来还原数据集. AOF 文件中的命令全部以 Redis 协议的格式来保存 ...

  9. 若a与m互质,则a不影响m的完全剩余组

    [若a与m互质,则a不影响m的完全剩余组] 设t通过m的完全剩余组,若at不通过m的完全剩余组, 则会有at1=at2(mod m),即a(t1-t2)|m. 因为(a,m)=1,所以(t1-t2)| ...

  10. canvas动画--demo

    canvas动画:bubble