Problem Description

Julius Caesar lived in a time of danger and intrigue. The hardest situation Caesar ever faced was keeping himself alive. In order for him to survive, he decided to create one of the first ciphers. This cipher was so incredibly sound, that no one could figure it out without knowing how it worked.

You are a sub captain of Caesar’s army. It is your job to decipher the messages sent by Caesar and provide to your general. The code is simple. For each letter in a plaintext message, you shift it five places to the right to create the secure message (i.e., if the letter is ‘A’, the cipher text would be ‘F’). Since you are creating plain text out of Caesar’s messages, you will do the opposite:

Cipher text

A B C D E F G H I J K L M N O P Q R S T U V W X Y Z

Plain text

V W X Y Z A B C D E F G H I J K L M N O P Q R S T U

Only letters are shifted in this cipher. Any non-alphabetical character should remain the same, and all alphabetical characters will be upper case.

Input

Input to this problem will consist of a (non-empty) series of up to 100 data sets. Each data set will be formatted according to the following description, and there will be no blank lines separating data sets. All characters will be uppercase.

A single data set has 3 components:

Start line - A single line, “START”

Cipher message - A single line containing from one to two hundred characters, inclusive, comprising a single message from Caesar

End line - A single line, “END”

Following the final data set will be a single line, “ENDOFINPUT”.

Output

For each data set, there will be exactly one line of output. This is the original message by Caesar.

Sample Input

START

NS BFW, JAJSYX TK NRUTWYFSHJ FWJ YMJ WJXZQY TK YWNANFQ HFZXJX

END

START

N BTZQI WFYMJW GJ KNWXY NS F QNYYQJ NGJWNFS ANQQFLJ YMFS XJHTSI NS WTRJ

END

START

IFSLJW PSTBX KZQQ BJQQ YMFY HFJXFW NX RTWJ IFSLJWTZX YMFS MJ

END

ENDOFINPUT

Sample Output

IN WAR, EVENTS OF IMPORTANCE ARE THE RESULT OF TRIVIAL CAUSES

I WOULD RATHER BE FIRST IN A LITTLE IBERIAN VILLAGE THAN SECOND IN ROME

DANGER KNOWS FULL WELL THAT CAESAR IS MORE DANGEROUS THAN HE

就是一个加密解密的过程;

import java.util.Scanner;

public class Main{
static char[] ctext =new char[26];
static char[] ptext =new char[26];
public static void main(String[] args) {
ctet();
Scanner sc = new Scanner(System.in);
while(sc.hasNext()){
String str = sc.nextLine();
if(str.equals("ENDOFINPUT")){
break;
}
//System.out.println("str="+str);
String strs = sc.nextLine();
// System.out.println("strs="+strs);
for(int i=0;i<strs.length();i++){
if(strs.charAt(i)>='A'&&strs.charAt(i)<='Z'){
for(int j=0;j<ctext.length;j++){
if(strs.charAt(i)==ctext[j]){
System.out.print(ptext[j]);
break;
}
} }else{
System.out.print(strs.charAt(i));
} }
System.out.println();
// String a = sc.nextLine();
// System.out.println("a = "+a);
String s = sc.nextLine();
//System.out.println("s = "+s); } }
private static void ctet() {
int k=0;
for(int i='A';i<='Z';i++){
ctext[k++]=(char)i;
}
String str = "V W X Y Z A B C D E F G H I J K L M N O P Q R S T U";
String strs[] = str.split(" +");
k=0;
for(int i='A';i<='Z';i++){
ptext[k] =strs[k].charAt(0);
k++;
}
} }

HDOJ 1048 The Hardest Problem Ever(加密解密类)的更多相关文章

  1. [C#] 常用工具类——加密解密类

    using System; using System.Configuration; using System.Collections.Generic; using System.Text; using ...

  2. 对接携程供应商php加密解密类

    php加密解密类 <?php class Aes{ private $key = '6b4d63211b4ba869'; private $iv = 'dbbf079b95004f65'; pu ...

  3. PHP针对数字的加密解密类,可直接使用

    <?phpnamespace app;/** * 加密解密类 * 该算法仅支持加密数字.比较适用于数据库中id字段的加密解密,以及根据数字显示url的加密. * @author 深秋的竹子 *  ...

  4. Java常用的加密解密类(对称加密类)

    Java常用的加密解密类 原文转载至:http://blog.csdn.net/wyc_cs/article/details/8793198 原创 2013年04月12日 14:33:35 1704 ...

  5. 生成二维码 加密解密类 TABLE转换成实体、TABLE转换成实体集合(可转换成对象和值类型) COOKIE帮助类 数据类型转换 截取字符串 根据IP获取地点 生成随机字符 UNIX时间转换为DATETIME\DATETIME转换为UNIXTIME 是否包含中文 生成秘钥方式之一 计算某一年 某一周 的起始时间和结束时间

    生成二维码 /// <summary>/// 生成二维码/// </summary>public static class QRcodeUtils{private static ...

  6. java文本文件加密解密类

    原文:http://www.open-open.com/code/view/1420031154765 import java.awt.*; import java.awt.event.*; impo ...

  7. AES对称加密解密类

    import java.io.UnsupportedEncodingException; import javax.crypto.Cipher; import javax.crypto.spec.Se ...

  8. 一个java的DES加密解密类转换成C#

    一个java的des加密解密代码如下: //package com.visionsky.util; import java.security.*; //import java.util.regex.P ...

  9. PHP加密解密类

    <?php class Mypass { static function encrypt($data, $key){ $key = md5($key); $x = 0; $len = strle ...

随机推荐

  1. Codeforces 540D Bad Luck Island - 概率+记忆化搜索

    [题意] 一个岛上有三种生物A,B,C,各有多少只在输入中会告诉你,每种最多100只 A与B碰面,A会吃掉B, B与C碰面,B会吃掉C, C与A碰面,C会吃掉A...忍不住想吐槽这种环形食物链 碰面是 ...

  2. [转] NSString / NSMutableString 字符串处理,常用代码

     原文 :  http://justcoding.iteye.com/blog/1405951 Objective-C 中核心处理字符串的类是 NSString 与 NSMutableString , ...

  3. UITabBarController自定义一

    UITabBarController自定义一 首先在Appdelegate.m文件中将UITabBarController的子类设置为rootViewController,并设置其viewContro ...

  4. <q>标签,短文本引用

    想在你的html中加一段引用吗?比如在你的网页的文章里想引用某个作家的一句诗,这样会使你的文章更加出彩,那么<q>标签是你所需要的. 语法: <q>引用文本</q> ...

  5. Swift - 24 - switch语句的高级用法

    //: Playground - noun: a place where people can play import UIKit // 对区间进行判断 var score = 90 switch s ...

  6. Action class [userAction] not found

    今天在做SSI框架整合的时候报了一个这样的错误:Action class [userAction] not found - action - file:F:\workspace\.metadata\. ...

  7. 【USACO 2.1.5】海明码

    [题目描述] 给出 N,B 和 D,要求找出 N 个由0或1组成的编码(1 <= N <= 64),每个编码有 B 位(1 <= B <= 8),使得两两编码之间至少有 D 个 ...

  8. Oracle 游标使用全解(转)

    转自:http://www.cnblogs.com/sc-xx/archive/2011/12/03/2275084.html 这个文档几乎包含了oracle游标使用的方方面面,全部通过了测试 -- ...

  9. 我的Jekyll博客

    我在GitHub Page上托管的Jekyll博客地址:http://lastavenger.github.io/

  10. hdu 1051Wooden Sticks

    #include<cstdio> #include<cstring> #include<algorithm> #define maxn 10000 using na ...