hdu1200(来来回回串起来)
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.
toioynnkpheleaigshareconhtomesnlewx
3
ttyohhieneesiaabss
0
thisistheeasyoneab
#include<stdio.h>
#include<string.h>
int main()
{
int n,i,len,m,e,j;
char str[10000],ch[1000][25];
while(scanf("%d",&n)==1&&n)
{
getchar();
scanf("%s",str);
len=strlen(str);
m=len/n;//把str串分成m个小串
if(len%n)
m++;
for(i=0;i<m;i++)
if(i%2==0)//当能被2整除的就正向保存
{
e=0;
for(j=i*n;j<len&&j<(i+1)*n;j++)
ch[i][e++]=str[j];
}
else//否则就倒着保存
{
e=0;
for(j=(i+1)*n-1;j>=i*n;j--)
if(str[j]!='\0')
ch[i][e++]=str[j];
}
e=len%n;//注意,有的不能除尽,最后一个小串长度小于n
for(j=0;j<n;j++)
for(i=0;i<m;i++)
if(i==m-1)//最后一个小串输出
{
if(j<e||e==0)
printf("%c",ch[i][j]);
}
else
printf("%c",ch[i][j]); printf("\n");
}
}
hdu1200(来来回回串起来)的更多相关文章
- ASP.NET MVC5+EF6+EasyUI 后台管理系统(62)-EF链接串加密
系列目录 前言: 这一节提供一个简单的功能,这个功能看似简单,找了一下没找到EF链接数据库串的加密帮助文档,只能自己写了,这样也更加符合自己的加密要求 有时候我们发布程序为了避免程序外的SQL链接串明 ...
- JQuery使用deferreds串行多个ajax请求
使用JQuery对多个ajax请求串行执行. HTML代码: <a href="#">Click me!</a> <div></div&g ...
- iOS 字典或者数组和JSON串的转换
在和服务器交互过程中,会iOS 字典或者数组和JSON串的转换,具体互换如下: // 将字典或者数组转化为JSON串 + (NSData *)toJSONData:(id)theData { NSEr ...
- iOS:GCD理解1(同步-异步、串行-并行)
1.并行-异步(ST1与ST2抢占资源) 1-1).获取 并行(全局)队列 ,DISPATCH_QUEUE_PRIORITY_DEFAULT 为默认优先级. dispatch_queue_t queu ...
- 关于用sql语句实现一串数字位数不足在左侧补0的技巧
在日常使用sql做查询插入操作时,我们通常会用到用sql查询一串编号,这串编号由数字组成.为了统一美观,我们记录编号时,统一指定位数,不足的位数我们在其左侧补0.如编号66,我们指定位数为5,则保存数 ...
- [LeetCode] Longest Palindrome 最长回文串
Given a string which consists of lowercase or uppercase letters, find the length of the longest pali ...
- [LeetCode] Shortest Palindrome 最短回文串
Given a string S, you are allowed to convert it to a palindrome by adding characters in front of it. ...
- [LeetCode] Palindrome Partitioning II 拆分回文串之二
Given a string s, partition s such that every substring of the partition is a palindrome. Return the ...
- [LeetCode] Palindrome Partitioning 拆分回文串
Given a string s, partition s such that every substring of the partition is a palindrome. Return all ...
随机推荐
- HTML::Entities 编码或解码 HTML 实体的字符串
<pre name="code" class="html"><pre name="code" class="py ...
- 在非MFC程序中使用调试宏 ASSERT(),VERIFY()和 TRACE()
游戏制作已经开始采用C++了,却鲜有人选择使用MFC.但笔者觉得的 ASSERT(),VERIFY()和 TRACE()这几个宏很好用.所以就想自己写一个版本来适应Windows平台下不同的工程类型. ...
- IT第五天 - 循环的使用、本周总结 ★★★
IT第五天 上午 循环 1.while循环.do-while循环.switch语句块的使用 下午 编程 1.编程注释的编写 2.编程力求代码的精简,算法的优化 3.变量的优化使用 小项目 1.swit ...
- 十句话教你学会Linux数据流重定向
1.看到重定向一下子就想起了web里面的redirect,没错,但是Linux数据流重定向的作用不是跳到另一个网页,而是用来存储重要的屏幕信息.将不必要的屏幕信息输出到文件里或者“黑洞”里.将错误信息 ...
- 移植FreeModbus+ModbusMaster+STM32至RT-Thread(3、4阶段)
一.简介及进展 经过一个多月的努力,目前项目开发已进入最后阶段.虽然比预期时间有些延迟,但也收获不少,边工作边开源的效率确实还有待提高. 简单说下目前的进展吧 1.目前项目已经在Github中开源,大 ...
- asp.net mvc 下载文件 txt doc xsl 等等
不废话,直接上代码,就是这么简单 public FileStreamResult StreamFileFromDisk() { // string path = AppDomain.Current ...
- [Swust OJ 247]--皇帝的新衣(组合数+Lucas定理)
题目链接:http://acm.swust.edu.cn/problem/0247/ Time limit(ms): 1000 Memory limit(kb): 65535 Descriptio ...
- Java Interface,反射
先看代码, package reflect; //Class Word public class Word implements OfficeAble{ public static void main ...
- ZOJ 2856 Happy Life 暴力求解
因为是Special Judge 的题目,只要输出正确答案即可,不唯一 暴力力求解, 只要每次改变 happiness 值为负的人的符号即可. 如果计算出当前人的 happiness 值为负,那么将其 ...
- CodeForces 385C Bear and Prime Numbers 素数打表
第一眼看这道题目的时候觉得可能会很难也看不太懂,但是看了给出的Hint之后思路就十分清晰了 Consider the first sample. Overall, the first sample h ...