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

水题。

译码还原问题

题目保证输入的数据一定是一个矩形的。

import java.util.Scanner;

public class Main{

    public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
while(sc.hasNext()){
int n=sc.nextInt();
if(n==0){
return;
}
String str=sc.next();
String s[] = new String[str.length()/n];
for(int i=0;i<str.length()/n;i++){
s[i]="";//不要忘记初始化
if(i%2==0){
for(int k=i*n;k<n+n*i;k++){
s[i]=s[i]+str.charAt(k);
}
}else{
for(int k=i*n;k<n+n*i;k++){
s[i]=str.charAt(k)+s[i];
}
}
//System.out.println(s[i]);
} for(int i=0;i<n;i++){
for(int k=0;k<s.length;k++){
System.out.print(s[k].charAt(i));
}
}
System.out.println(); } } }

HDOJ/HDU 1200 To and Fro(加密解密字符串)的更多相关文章

  1. PHP的加密解密字符串函数

    程序中经常使用的PHP加密解密字符串函数 代码如下: /********************************************************************* 函数 ...

  2. php 加密解密字符串

    /********************************************************************* 函数名称:encrypt 函数作用:加密解密字符串 使用方 ...

  3. Java加密解密字符串

    http://www.cnblogs.com/vwpolo/archive/2012/07/18/2597232.html Java加密解密字符串   旧文重发:http://www.blogjava ...

  4. django删除表重建&修改用户密码&base64加密解密字符串&ps aux参数说明&各种Error例子

    1.django的queryset不支持负索引 AssertionError: Negative indexing is not supported. 2.django向前端JavaScript传递列 ...

  5. PHP_加密解密字符串

    PHP_加密解密字符串.php <?php //加解密字符串函数,可以加密中文 /* //加密 echo $encode = authcode('爱迪生', 'ENCODE', '3'); // ...

  6. 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 ...

  7. HDOJ 1048 The Hardest Problem Ever(加密解密类)

    Problem Description Julius Caesar lived in a time of danger and intrigue. The hardest situation Caes ...

  8. PHP加密解密字符串

    项目中有时我们需要使用PHP将特定的信息进行加密,也就是通过加密算法生成一个加密字符串,这个加密后的字符串可以通过解密算法进行解密,便于程序对解密后的信息进行处理. 最常见的应用在用户登录以及一些AP ...

  9. [DEncrypt] RSACryption--RSA加密/解密字符串 (转载)

    点击下载 RSACryption.zip 这个类是关于加密,解密的操作,文件的一些高级操作1.RSACryption RSA 的密钥产生2.RSACryption RSA的加密函数3.RSACrypt ...

随机推荐

  1. bzoj3571: [Hnoi2014]画框 最小乘积匹配+最小乘积XX总结,

    思路大概同bzoj2395(传送门:http://www.cnblogs.com/DUXT/p/5739864.html),还是将每一种匹配方案的Σai看成x,Σbi看成y,然后将每种方案转化为平面上 ...

  2. cocos2d-x使用DragonBones动画

    前言 在网上查找关于DragonBones在cocos2d-x的使用教程,找了大半天也没有找到一个有用的.在自己摸索了一段时间终于摸索了出来,在这里记下分享给大家. 下载DragonBones 我这里 ...

  3. Nginx(一)初始环境的安装(php5.3+mysql5.1+fastcgi…)

    关参考资源http://www.lnmp.org/index.html \\LNMP一键安装包http://www.howtocn.org/nginx \\Nginx模块参考手册中文版http://b ...

  4. /etc/rc.local ; /etc/init.d ;/etc/profile;/etc/bashrc;~/.bash_profile;~/.bashrc;~/.bash_logout

    1. /etc/rc.local 这是使用者自订开机启动程序,把需要开机自动运行的程序写在这个脚本里. 把脚本程序写在/etc/rc.d/init.d/目录下也可以  在完成 run level 3 ...

  5. 禁止选择文本和禁用右键 v3.0

    禁止选中字体(注:在火狐浏览器没有起到效果作用) <script> function disableselect(e) { var omitformtags = ["input& ...

  6. DelphiXE4- System.IOUtils.TDirectory笔记查询后缀名为dll的文件

    TStringDynArray 在System.Types中定义

  7. python三级菜单的实现

    一.作业要求 1.使用字典实现三级菜单功能 2.直接输入前面数字进入下一级菜单 3.按B返回上一级,按Q退出 二.需要知识点 1.if循环 2.for循环,enumerate的用法 3.while循环 ...

  8. odoo 的 拉式 和 推式 库链

    推式链的数据定义在  stock.location.path 表,视图定义在 “路线” 界面的 “push rules” 具体可参考  入库设置为  Receipt in 2 steps . push ...

  9. lucene解决全文检索word2003,word2007的办法

    在上一篇文章中 ,lucene只能全文检索word2003,无法检索2007,并且只能加载部分内容,无法加载全文内容.为解决此问题,找到了如下方法 POI 读取word (word 2003 和 wo ...

  10. E8.ITSM IT运维服务管理系统

      一.     IT运维面临问题 随着企业信息化项目若干年以来的建设积累,IT资产日趋庞大,以及内外部监管部门对IT运维的要求也越来越严格规范,业务部门对企业的IT运维管理也提出了更高的要求. IT ...