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. Codevs 1217 借教室 2012年NOIP全国联赛提高组

    1217 借教室 2012年NOIP全国联赛提高组 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 钻石 Diamond 题目描述 Description 在大学期间,经常需要租借教 ...

  2. Jquery环境搭建前言

  3. 在类库或winform项目中打开另一个winform项目的窗体

    假设类库或winform项目为A,另一个winform项目为B.那麽在A中添加一个接口,里面有一个Show方法,然后在B中写一个类b继承这个接口,并重写这个方法,具体内容为弹出某个窗体.然后在A中另一 ...

  4. 在Windows下不使用密码远程登陆Linux

    在登陆Linux进行管理的时候我们通常会使用用户名和密码进行登陆,这样一来是比较麻烦,二来是不安全,为了解决这个问题,我们可以使用公私钥 (public keys和private keys)进行认证. ...

  5. 以查询方式实现1s定时

    以查询控制器的控制位状态来实现1s定时. #include <reg52.h> sbit LED = P0^; unsigned ; void main () { LED = ; // 点 ...

  6. 使用GetLogicalDriveStrings获取驱动器根路径

    使用GetLogicalDriveStrings获取驱动器根路径,并使用自定义的GetDriveInfo函数获取驱动器的属性. VS2012 + win7 x64下调试通过. #include < ...

  7. 一个Highcharts的例子

    关键字:Highcharts <!DOCTYPE HTML> <html> <head> <meta http-equiv="Content-Typ ...

  8. c#中struct和class的区别 z

    1.struct 是值类型,class是对象类型 2.struct 不能被继承,class可以被继承 3.struct 默认的访问权限是public,而class默认的访问权限是private. 4. ...

  9. POJ 3687 Labeling Balls 逆向建图,拓扑排序

    题目链接: http://poj.org/problem?id=3687 要逆向建图,输入的时候要判重边,找入度为0的点的时候要从大到小循环,尽量让编号大的先入栈,输出的时候注意按编号的顺序输出重量, ...

  10. BZOJ 1668: [Usaco2006 Oct]Cow Pie Treasures 馅饼里的财富

    Description 最近,奶牛们热衷于把金币包在面粉里,然后把它们烤成馅饼.第i块馅饼中含有Ni(1<=Ni<=25)块金币,并且,这个数字被醒目地标记在馅饼表面. 奶牛们把所有烤好的 ...