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 ...
随机推荐
- 7月19日Docker&Kubernetes技术沙龙总结 - DockOne.io
7月19日Docker&Kubernetes技术沙龙总结 - DockOne.io undefined
- hdoj 2767 Proving Equivalences【求scc&&缩点】【求最少添加多少条边使这个图成为一个scc】
Proving Equivalences Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Oth ...
- 16个最棒的jQuery视差滚动效果教程
今天我们整理了16个最棒的jQuery视差滚动效果教程 , 并附有演示地址,你可以快速的查看教程的效果,或者应用在自己的项目中.希望本文对想要学习或者使用jQuery视差效果的朋友有帮助,慢慢的欣赏吧 ...
- cocos2d-x 2.1.4 使用create_project.py脚本创建项目+ant打包项目
1.创建项目:执行create_project.py脚本,进入Doc界面输入下面的命令: cd D:\cocos2d-x-2.1.4\cocos2d-x-2.1.4\tools\project-cre ...
- Clojure学习资料
以下大部分收藏自博客:http://blog.csdn.net/ithomer/article/details/17225813 官方文档: http://clojure.org/documentat ...
- jetty之建立多Connector
转自:http://blog.csdn.net/kongxx/article/details/7218787 在嵌入运行Jetty的时候,有时候想要启动两个端口,或者通过一个Jetty server提 ...
- 20169210《Linux内核原理与分析》第八周作业
第一部分:实验 首先还是网易云课堂的学习,这次的课程是进程的创建和进程的描述. linux进程的状态与操作系统原理中的描述的进程状态有些不同,例如就绪状态和运行状态都是TASK_RUNNING. Li ...
- linux系统下安装apache与tomcat
apache的安装 把安装包放到/soft 下 [root@localhost ~]#cd /soft [root@localhost soft]#tar jxvf httpd-2.2.25.tar. ...
- [Webpack 2] Chunking common modules from multiple apps with the Webpack CommonsChunkPlugin
If you have a multi-page application (as opposed to a single page app), you’re likely sharing module ...
- expect批量分发公钥
sshkey.exp #!/usr/bin/expect# 由于是多台服务器,需要在shell脚本中循环调用该脚本 if { $argc != 2 } { send_user "usage: ...