To and Fro

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 5485    Accepted Submission(s): 3795

Problem Description
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.
 
Sample Input
5 toioynnkpheleaigshareconhtomesnlewx
3 ttyohhieneesiaabss
0
 
Sample Output
theresnoplacelikehomeonasnowynightx
thisistheeasyoneab
 
此题先将输入的数据转化为二维数组再将数组按列输出即可(数组的列数即为字符串前所输的数)
#include<stdio.h>
#include<string.h>
int main()
{
int n,m,j,i,t,l,k;
char str[1100];
char s[100][100];
while(scanf("%d",&t)&&t!=0)
{
getchar();
gets(str);
l=strlen(str);
k=0;j=0;
for(i=0;i<l;i++)
{
if(k%2==0)
{
s[k][j]=str[i];
j++;
if(j==t)
k++;
}
else
{
s[k][j-1]=str[i];
j--;
if(j==0)
k++;
}
}
for(i=0;i<t;i++)
{
for(j=0;j<k;j++)
{
printf("%c",s[j][i]);
}
}
printf("\n");
}
return 0;
}

hdoj 1200 To and Fro的更多相关文章

  1. [acm]HDOJ 1200 To and Fro

    题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=1200 简单字符串处理,找规律 /* 11509672 2014-08-21 11:32:55 Acc ...

  2. hdu 1200 To and Fro(简单模拟或DP)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1200 To and Fro Time Limit: 2000/1000 MS (Java/Others ...

  3. HDOJ/HDU 1200 To and Fro(加密解密字符串)

    Problem Description Mo and Larry have devised a way of encrypting messages. They first decide secret ...

  4. HDU - 1200 To and Fro

    题意:给定一个,其实是由一个图按蛇形输出而成的字符串,要求按从左到右,从上到下的顺序输出这个图. 分析: 1.把字符串转化成图 2.按要求输出图= = #include<cstdio> # ...

  5. 杭电hdoj题目分类

    HDOJ 题目分类 //分类不是绝对的 //"*" 表示好题,需要多次回味 //"?"表示结论是正确的,但还停留在模块阶 段,需要理解,证明. //简单题看到就 ...

  6. HDOJ 题目分类

    HDOJ 题目分类 /* * 一:简单题 */ 1000:    入门用:1001:    用高斯求和公式要防溢出1004:1012:1013:    对9取余好了1017:1021:1027:   ...

  7. HDU字符串基础题(1020,1039,1062,1088,1161,1200,2017)

    并不是很精简,随便改改A过了就没有再简化了. 1020. Problem Description Given a string containing only 'A' - 'Z', we could ...

  8. HDOJ 1009. Fat Mouse' Trade 贪心 结构体排序

    FatMouse' Trade Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  9. HDOJ 2317. Nasty Hacks 模拟水题

    Nasty Hacks Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Tota ...

随机推荐

  1. SQL Trigger(触发器)

    1.触发器对表进行插入.更新.删除的时候会自动执行的特殊存储过程. 2.触发器一般用在check约束更加复杂的约束上面. 3.触发器和普通的存储过程的区别是:触发器是当对某一个表进行操作. 4.upd ...

  2. 由json生成php配置文件

    $str = '<?php return ' . var_export(json_decode($json, true), true) . ';';file_put_contents('./co ...

  3. Pentaho Data Integration Step: BD Procedure Call

    官网连接:http://wiki.pentaho.com/display/EAI/Call+DB+Procedure 描述 调用数据库存储过程步骤允许用户执行一个数据库存储过程,并且得到结果.存储过程 ...

  4. spring mvc 配置

    之前配置spring mvc 怎么都访不到对应的jsp,后来把prefix里面的jsp改为views,就能访问到了,然后再改回jsp也可以访问到 搞了两天,都崩溃了,不管怎样先把没问题的例子给记录下来 ...

  5. HDU 4734

    数位dp题:也是我做的第一个数位dp的题目: 感觉数位dp的模板性很强啊,思想都差不太多! 有几个写的很好的参考资料: 推荐一下: 数位计数问题解法研究 浅谈数位类统计问题 我的代码: #includ ...

  6. 基于Visual C++6.0的DLL编程实现

    整理自基于Visual C++6.0的DLL编程实现 本文通过通俗易懂的方式,全面介绍了动态链接库的概念.动态链接库的创建和动态链接库的链接,并给出个简单明了的例子,相信读者看了本文后,能够创建自己的 ...

  7. SEO 网站URL优化

    很多人都知道URL对SEO的重要之处,但是很多站点却忽略了站点的路径优化.今天本人在这里写几点关于优化路径小篇! 本人结论出关于站点URL在优化中其实也是占为一个相当重要的一个优化!优化站点的URL本 ...

  8. POJ_2446_Chessboard

    题目意思就是一个M*N的有洞棋盘棋盘上,用1*2的板子去覆盖没有洞的地方,要求板子不能重叠,最终能否将棋盘完整覆盖. 代码: #include<stdio.h> #include<s ...

  9. 李洪强漫谈iOS开发[C语言-032]-三目运算符

  10. MySQL查询原理及其慢查询优化案例分享(转)

    MySQL凭借着出色的性能.低廉的成本.丰富的资源,已经成为绝大多数互联网公司的首选关系型数据库.虽然性能出色,但所谓“好马配好鞍”,如何能够更 好的使用它,已经成为开发工程师的必修课,我们经常会从职 ...