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

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

  1. import java.util.Scanner;
  2. public class Main{
  3. static char[] ctext =new char[26];
  4. static char[] ptext =new char[26];
  5. public static void main(String[] args) {
  6. ctet();
  7. Scanner sc = new Scanner(System.in);
  8. while(sc.hasNext()){
  9. String str = sc.nextLine();
  10. if(str.equals("ENDOFINPUT")){
  11. break;
  12. }
  13. //System.out.println("str="+str);
  14. String strs = sc.nextLine();
  15. // System.out.println("strs="+strs);
  16. for(int i=0;i<strs.length();i++){
  17. if(strs.charAt(i)>='A'&&strs.charAt(i)<='Z'){
  18. for(int j=0;j<ctext.length;j++){
  19. if(strs.charAt(i)==ctext[j]){
  20. System.out.print(ptext[j]);
  21. break;
  22. }
  23. }
  24. }else{
  25. System.out.print(strs.charAt(i));
  26. }
  27. }
  28. System.out.println();
  29. // String a = sc.nextLine();
  30. // System.out.println("a = "+a);
  31. String s = sc.nextLine();
  32. //System.out.println("s = "+s);
  33. }
  34. }
  35. private static void ctet() {
  36. int k=0;
  37. for(int i='A';i<='Z';i++){
  38. ctext[k++]=(char)i;
  39. }
  40. 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";
  41. String strs[] = str.split(" +");
  42. k=0;
  43. for(int i='A';i<='Z';i++){
  44. ptext[k] =strs[k].charAt(0);
  45. k++;
  46. }
  47. }
  48. }

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. Qt国际化详细介绍,中文乱码以及解决方案

    Qt国际化的一般步骤 运行 lupdate,从应用程序的代码中提取所有界面上的可见字符.        这些可见字符必须被 tr() .QCoreApplication::translate().Qt ...

  2. RESTEasy + JBOSS 7 Hello world application---reference

    RESTEasy is JBOSS provided implementation of JAX-RS specification for building RESTful Web Services  ...

  3. masonry使用介绍

    Masonry使用介绍 下面是Masonry的代码地址:https://github.com/Masonry/Masonry 介绍一个简单使用: <pre><code>[vie ...

  4. [转] C++指针加整数、两个指针相减的问题

    http://blog.csdn.net/onlyou930/article/details/6725051 说来惭愧,写C++有一段时间了.这个问题从来没有认真考虑过,此次标记于此: 考虑如下问题: ...

  5. MyBatis 学习总结(二)

    1.MyBatis基础环境的搭建 1.1 核心配置文件mybatis-config.xml <?xml version="1.0" encoding="UTF-8& ...

  6. MyBatis 学习总结(一)

    1.原生JDBC(Java database connectity)操作数据库(以MySQL数据为例)步骤 1.1 加载驱动 Class.forName("com.mysql.jdbc.Dr ...

  7. JSON 解析(门店)

    package com.j1.mai.action; import java.io.BufferedReader; import java.io.IOException; import java.io ...

  8. HighCharts基本用法

    var options={ chart: {type: 'column',renderTo: 'ChartDesigner1'},//type :图表类型(柱状图,饼状图),renderTo :指向页 ...

  9. (转)Div左右两侧等高

    一. 利用背景图,做出左右等高的模拟效果   这种方法不是真正的左右等高,而是在外框元素中添加一张背景图片,当内容增多时,背景会纵向重复,就会形成左右等高的效果. 这种方法不是真正的div自动等高,而 ...

  10. JavaScript ArrayBuffer浅析

    时隔一年半,再次来到博客园.回首刚接触前端时所写的两篇随笔,无法直视啊~ --------------------------------------------------------------- ...