ZOJ2208 To and Fro 2017-04-16 19:30 45人阅读 评论(0) 收藏
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) 收藏的更多相关文章
- HDU6029 Happy Necklace 2017-05-07 19:11 45人阅读 评论(0) 收藏
Happy Necklace Time Limit: ...
- HDU6026 Deleting Edges 2017-05-07 19:30 38人阅读 评论(0) 收藏
Deleting Edges Time ...
- 滑雪 分类: POJ 2015-07-23 19:48 9人阅读 评论(0) 收藏
滑雪 Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 83276 Accepted: 31159 Description Mich ...
- HDU6027 Easy Summation 2017-05-07 19:02 23人阅读 评论(0) 收藏
Easy Summation Time Limit: 2000/1000 MS ...
- 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 ...
- IP Address 分类: POJ 2015-06-12 19:34 12人阅读 评论(0) 收藏
IP Address Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 19125 Accepted: 11053 Desc ...
- 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 ...
- 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 ...
- 利用YaHoo YUI实现Javascript CSS 压缩 分类: C# 2014-07-13 19:07 371人阅读 评论(0) 收藏
网站优化时,往往需要对js文件,css文件进行压缩,以达到减少网络传输数据,减少网页加载时间:利用YaHoo的YUI可以实现Javascript,CSS,压缩,包括在线的js压缩和程序压缩,发现C#也 ...
随机推荐
- python 下载图片的方法
a='http://wx1.sinaimg.cn/mw600/006HOayNgy1fqjdi2nxohj32pw3o8x6s.jpg' #图片下载地址 ( 这里改成 文件txt地址)w='/U ...
- pythonNetday06
进程 Process(target,name,args,kwargs) p.pid : 创建的新的进程的PID号 p.is_alive() 判断进程是否处于alive状态 p.daemon = Tru ...
- jquery文件的引入
上节课说到,一般情况下,是库的文件,该库中都会抛出来构造函数或者对象 ,如果是构造函数,那么创建对象,如果是对象直接调用属性和方法 使用jquery第一步,先引入jquery,然后再写相应的jquer ...
- maven settings.xml 文件
指定jdk 的版本: <profile> <id>jdk-1.8</id> <activation> <activeByDefault>tr ...
- InnoDB: The log sequence number in ibdata files does not match
InnoDB: The log sequence number in ibdata files does not matchInnoDB的:在ibdata文件的日志序列号不匹配 可能ibdata文件损 ...
- Redis 主从分离
首先配置redis.conf文件如下6个位置 cp 多个redis.conf文件 开启daemonize yes PID文件名字 端口 log文件名字 dump.rdb名字 配置: 主机不动,配置从机 ...
- Node.js 项目打包
Node项目基于Electron打包 Electron打包打包后项目.exe程序包含在文件夹中,基于Electron打包的基础上直接打包成exe程序 参考一 参考二 需求的软件环境: NSIS 2.4 ...
- LevelDB Filters
[LevelDB Filters] Because of the way leveldb data is organized on disk, a single Get() call may invo ...
- go_goroutine and channel
协程Coroutine 轻量级”线程“ 非抢占式多任务处理,由协程主动交出控制权(如果程序中间没有print,程序会一直霸占着调度器) 编译器/解释器/虚拟机层面的多任务 多个协程可能在一个或多个线程 ...
- UNITY5 为什么Inspector视图中脚本前面的勾选框没了
结果发现了一个奇葩的问题..凡事脚本没有勾选项的,都是因为你的脚本没有Start方法..如果你想让勾选框显示出来,把如下方法加入即可,不信你可以试试.嘿嘿.