HDOJ 1048 The Hardest Problem Ever(加密解密类)
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(加密解密类)的更多相关文章
- [C#] 常用工具类——加密解密类
using System; using System.Configuration; using System.Collections.Generic; using System.Text; using ...
- 对接携程供应商php加密解密类
php加密解密类 <?php class Aes{ private $key = '6b4d63211b4ba869'; private $iv = 'dbbf079b95004f65'; pu ...
- PHP针对数字的加密解密类,可直接使用
<?phpnamespace app;/** * 加密解密类 * 该算法仅支持加密数字.比较适用于数据库中id字段的加密解密,以及根据数字显示url的加密. * @author 深秋的竹子 * ...
- Java常用的加密解密类(对称加密类)
Java常用的加密解密类 原文转载至:http://blog.csdn.net/wyc_cs/article/details/8793198 原创 2013年04月12日 14:33:35 1704 ...
- 生成二维码 加密解密类 TABLE转换成实体、TABLE转换成实体集合(可转换成对象和值类型) COOKIE帮助类 数据类型转换 截取字符串 根据IP获取地点 生成随机字符 UNIX时间转换为DATETIME\DATETIME转换为UNIXTIME 是否包含中文 生成秘钥方式之一 计算某一年 某一周 的起始时间和结束时间
生成二维码 /// <summary>/// 生成二维码/// </summary>public static class QRcodeUtils{private static ...
- java文本文件加密解密类
原文:http://www.open-open.com/code/view/1420031154765 import java.awt.*; import java.awt.event.*; impo ...
- AES对称加密解密类
import java.io.UnsupportedEncodingException; import javax.crypto.Cipher; import javax.crypto.spec.Se ...
- 一个java的DES加密解密类转换成C#
一个java的des加密解密代码如下: //package com.visionsky.util; import java.security.*; //import java.util.regex.P ...
- PHP加密解密类
<?php class Mypass { static function encrypt($data, $key){ $key = md5($key); $x = 0; $len = strle ...
随机推荐
- iOS仿喜马拉雅FM做的毕业设计及总结(含新手福利源码)
其实仿喜马拉雅FM很早就开始了,从我刚接触iOS开始,就开始仿做了一部分,眼尖的人都从我的github找到了那个项目.随着找到实习iOS工作,仿写就落下了,但唯一的收获就是给过去打了一个响亮的耳光,因 ...
- 构建服务端的AMD/CMD模块加载器
本文原文地址:http://trock.lofter.com/post/117023_1208040 . 引言: 在前端开发领域,相信大家对AMD/CMD规范一定不会陌生,尤其对requireJS. ...
- 前后台使用ajax传list的时候,用value[] 获取值
使用json进行前后台交互的时候,如果穿过来是的是list,可以通过value[index],(index表示的是下标) //加载新闻 function jzxw(){ $.ajax( { type ...
- C# 实现文件夹的复制以及删除
代码来源:http://blog.163.com/u_tommy_520/blog/static/20406104420147493933662/ http://www.cnblogs.com/lov ...
- 开始编写正式的iOS 程序(iOS编程指导)
App设计基础 在确定了你的App主要功能后,需要把它转化为代码.如果你是第一次开发属于自己的iOS App,需要花些时间熟悉基本概念.iOS内置了很多设计样式,多了解下能对你以后有帮助. 初稿 设计 ...
- mysql启动不了:ERROR 2002 (HY000): Can’t connect to local MySQL server through socket
ps aux |grep mysql kill所有列出的进程,然后重启 service mysql start 原因有可能是mysqld没启动:service mysqld start. 持续出现此问 ...
- 将与系统时间格式不同的字符串格式化为DATETIME类型
若系统时间格式为2012/03/05 08:12:12,那么若将("2012-03-05 08:12:12")格式化为时间变量时会报错,在转化之前先将系统时间格式改变再转换就不会报 ...
- php 使用phpqrcode类生成带有logo的二维码 使logo不失真(透明)
在开发中 发现phpqrcode类在加入logo时,如果 logo 是 png 图像带有透明区域时,二维码上都无法正常完美的显示出来 解决方法便是:修改phpqrcode文件中的 QRimage类下的 ...
- jquery easy ui 学习 (7) TreeGrid Actions
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...
- 织梦DedeCMS子目录移动到根目录的方法
有时候我们在子目录中安装了dedecms,但有时候需要将其换到根目录中,下面就讲一下织梦DedeCMS子目录移动到根目录的方法: 下面是具体的操作步骤,强烈建议先备份数据库. 1.进入dedecms后 ...