POJ 2039 To and Fro(模拟)
To and Fro
Description
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
Output
Sample Input
5
toioynnkpheleaigshareconhtomesnlewx
3
ttyohhieneesiaabss
0
Sample Output
theresnoplacelikehomeonasnowynightx
thisistheeasyoneab 题目大意:
给出2<=N<=20和加密过的字符串(长度<=200),输出解密后的字符串。
加密规则:例如theresnoplacelikehomeonasnowynightx,按列写出,共N列
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
再按照奇数行,左至右,偶数行,右到左的顺序按行写出即可
代码如下:
# include<stdio.h>
# include<string.h>
# define MAX
int n,m;
char s[MAX],ans[MAX][MAX];
int main(){
int i,j;
while(scanf("%d",&n) && n){
scanf("%s",s);
m = strlen(s)/n;
int cnt=;
for(i=; i<=m; i++){
if(i%)
for(j=; j<=n; j++)
ans[i][j] = s[cnt++];
else
for(j=n; j>=; j--)
ans[i][j] = s[cnt++];
}
for(i=; i<=n; i++)
for(j=; j<=m; j++)
printf("%c",ans[j][i]);
puts("");
}
return ;
}
POJ 2039 To and Fro(模拟)的更多相关文章
- POJ 2039 To and Fro
To and Fro Description Mo and Larry have devised a way of encrypting messages. They first decide sec ...
- POJ 2039:To and Fro
To and Fro Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 8632 Accepted: 5797 Descri ...
- poj 1008:Maya Calendar(模拟题,玛雅日历转换)
Maya Calendar Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 64795 Accepted: 19978 D ...
- POJ 1027 The Same Game(模拟)
题目链接 题意 : 一个10×15的格子,有三种颜色的球,颜色相同且在同一片内的球叫做cluster(具体解释就是,两个球颜色相同且一个球可以通过上下左右到达另一个球,则这两个球属于同一个cluste ...
- POJ 3414 Pots【bfs模拟倒水问题】
链接: http://poj.org/problem?id=3414 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=22009#probl ...
- poj 2632 Crashing Robots(模拟)
链接:poj 2632 题意:在n*m的房间有num个机器,它们的坐标和方向已知,现给定一些指令及机器k运行的次数, L代表机器方向向左旋转90°,R代表机器方向向右旋转90°,F表示前进,每次前进一 ...
- poj 1028 Web Navigation(模拟)
题目链接:http://poj.org/problem? id=1028 Description Standard web browsers contain features to move back ...
- POJ 3087 Shuffle'm Up (模拟+map)
题目链接:http://poj.org/problem?id=3087 题目大意:已知两堆牌s1和s2的初始状态, 其牌数均为c,按给定规则能将他们相互交叉组合成一堆牌s12,再将s12的最底下的c块 ...
- POJ 1068 Parencodings【水模拟--数括号】
链接: http://poj.org/problem?id=1068 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=27454#probl ...
随机推荐
- 再也不用担心ie下console.log报错了。。。
习惯了在ff或者chrome下暴力调试的你会不会忘记注释掉而在ie下报错呢,那么可以加这个代码: if (typeof console == "undefined") { this ...
- iphone上click事件不触发的问题解决。
iphone上click事件不触发的问题解决. //在ID为jsProvince上有这么一个事件: $('body').on('click', '#jsProvince', function(e){ ...
- add-apt-repository cloud-archive:liberty
apt-get update && apt-get upgrade;
- C标准库简单解读
1,程序运行时动态链接共享库; libc(character),libm(math),使用标准库的函数; eg:stdlib.h exit(); size_t数据类型,NULL空指针在头文件stdde ...
- 《神经网络和深度学习》系列文章三:sigmoid神经元
出处: Michael Nielsen的<Neural Network and Deep Leraning>,点击末尾“阅读原文”即可查看英文原文. 本节译者:哈工大SCIR硕士生 徐伟 ...
- javascript排序 查找算法大全
在pptv的实习结束了, 忙着找工作的事,顺便把数据结构的那本书重新复习了一遍.为了加深印象,特意把里面的常用的排序.查找算法用js写了一遍 具体的实例在我的github上,大家可以访问的: http ...
- oracle10g前期准备
上午在虚拟机安装了oracle10g,安装比较简单,只是前期工作比较多,如: 在Root用户下执行以下步骤: 1)修改用户的SHELL的限制,修改/etc/security/limits.conf文件 ...
- WordPress文件上传与下载问题解决
网上流传了一些修改WordPress文件上传大小限制的做法,大部分是一个版本,而且说得不够准确,特别是对于生手的指导性不强,本文总结了使用Wordpress博客的朋友在文件上传与下载时大小限制,及文件 ...
- DIV+CSS布局-固定页面开度布局
DIV+CSS布局中主要CSS属性介绍: Float: Float属性是DIV+CSS布局中最基本也是最常用的属性,用于实现多列功能,我们知道<div>标签默认一行只能显示一个,而使用Fl ...
- PTA 06-图3 六度空间 (30分)
"六度空间"理论又称作"六度分隔(Six Degrees of Separation)"理论.这个理论可以通俗地阐述为:"你和任何一个陌生人之间所间隔 ...