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

简介: Problem Description Mo and Larry have devised a way of encrypting messages. They first decide secretly on the number of columns and write ...

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();

        }

    }

}
目录
相关文章
|
Unix Linux Shell
关于用strace工具定位vrrpd进程有时会挂死的bug
只做工作总结备忘之用。 正在烧镜像,稍总结一下进来改bug遇到的问题。     一个项目里要用到L3 switch的nat,vrrp功能,但实地测试中偶然出现write file挂死的情况,但不是必现。
1692 0
|
8天前
|
人工智能 JSON 供应链
畅用7个月无影 JVS Claw |手把手教你把JVS改造成「科研与产业地理情报可视化大师」
LucianaiB分享零成本畅用JVS Claw教程(学生认证享7个月使用权),并开源GeoMind项目——将JVS改造为科研与产业地理情报可视化AI助手,支持飞书文档解析、地理编码与腾讯地图可视化,助力产业关系图谱构建。
23428 9
畅用7个月无影 JVS Claw |手把手教你把JVS改造成「科研与产业地理情报可视化大师」
|
17天前
|
缓存 人工智能 自然语言处理
我对比了8个Claude API中转站,踩了不少坑,总结给你
本文是个人开发者耗时1周实测的8大Claude中转平台横向评测,聚焦Claude Code真实体验:以加权均价(¥/M token)、内部汇率、缓存支持、模型真实性及稳定性为核心指标。
6468 25
|
12天前
|
人工智能 缓存 BI
Claude Code + DeepSeek V4-Pro 真实评测:除了贵,没别的毛病
JeecgBoot AI专题研究 把 Claude Code 接入 DeepSeek V4Pro,跑完 Skills —— OA 审批、大屏、报表、部署 5 大实战场景后的真实体验 ![](https://oscimg.oschina.net/oscnet/up608d34aeb6bafc47f
4171 13
Claude Code + DeepSeek V4-Pro 真实评测:除了贵,没别的毛病
|
13天前
|
人工智能 JSON BI
DeepSeek V4 来了!超越 Claude Sonnet 4.5,赶紧对接 Claude Code 体验一把
JeecgBoot AI专题研究 把 Claude Code 接入 DeepSeek V4Pro 的真实体验与避坑记录 本文记录我将 Claude Code 对接 DeepSeek 最新模型(V4Pro)后的真实体验,测试了 Skills 自动化查询和积木报表 AI 建表两个场景——有惊喜,也踩
5017 13
|
29天前
|
人工智能 自然语言处理 安全
Claude Code 全攻略:命令大全 + 实战工作流(建议收藏)
本文介绍了Claude Code终端AI助手的使用指南,主要内容包括:1)常用命令如版本查看、项目启动和更新;2)三种工作模式切换及界面说明;3)核心功能指令速查表,包含初始化、压缩对话、清除历史等操作;4)详细解析了/init、/help、/clear、/compact、/memory等关键命令的使用场景和语法。文章通过丰富的界面截图和场景示例,帮助开发者快速掌握如何通过命令行和交互界面高效使用Claude Code进行项目开发,特别强调了CLAUDE.md文件作为项目知识库的核心作用。
23252 65
Claude Code 全攻略:命令大全 + 实战工作流(建议收藏)