HDOJ1048 The Hardest Problem Ever
来源:互联网 发布:淘宝司法拍卖房产过户 编辑:程序博客网 时间:2024/05/20 04:15
The Hardest Problem Ever
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 28637 Accepted Submission(s): 13407
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.
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".
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
STARTNS BFW, JAJSYX TK NRUTWYFSHJ FWJ YMJ WJXZQY TK YWNANFQ HFZXJXENDSTARTN BTZQI WFYMJW GJ KNWXY NS F QNYYQJ NGJWNFS ANQQFLJ YMFS XJHTSI NS WTRJENDSTARTIFSLJW PSTBX KZQQ BJQQ YMFY HFJXFW NX RTWJ IFSLJWTZX YMFS MJENDENDOFINPUT
Sample Output
IN WAR, EVENTS OF IMPORTANCE ARE THE RESULT OF TRIVIAL CAUSESI WOULD RATHER BE FIRST IN A LITTLE IBERIAN VILLAGE THAN SECOND IN ROMEDANGER KNOWS FULL WELL THAT CAESAR IS MORE DANGEROUS THAN HE
给一行字符,如果是A~Z就向前5位(就是ASCII码减5,超过了A就加26)
如果是START,END就不管他,如果是ENDOFINPUT就退出程序
import java.util.Scanner;public class Main{private static Scanner scanner;public static void main(String[] args) {scanner = new Scanner(System.in);while (scanner.hasNext()) {String line = scanner.nextLine();//如果是START,END就不管他,如果是ENDOFINPUT就退出程序if(line.equals("START")||line.equals("END")){continue;}else if (line.equals("ENDOFINPUT")) {break;}char[] ch = line.toCharArray();for (int i = 0; i < ch.length; i++) {//如果不是A~Z不需要修改if (ch[i] >= 'A' && ch[i] <= 'Z') {ch[i] -= 5;if (ch[i] < 'A') {//这是一个循环的过程ch[i] += 26;}}}for (char c : ch) { System.out.print(c);}System.out.println();}}}
阅读全文
0 0
- HDOJ1048 The Hardest Problem Ever
- HDOJ1048 The Hardest Problem Ever
- hdoj1048 The Hardest Problem Ever(字符转换)
- The Hardest Problem Ever
- The Hardest Problem Ever
- The Hardest Problem Ever
- The Hardest Problem Ever
- The Hardest Problem Ever
- The Hardest Problem Ever
- The Hardest Problem Ever
- The Hardest Problem Ever
- The Hardest Problem Ever
- The Hardest Problem Ever
- The Hardest Problem Ever
- The Hardest Problem Ever
- HDU1048 The Hardest Problem Ever
- 1048 The Hardest Problem Ever
- POJ1298 The Hardest Problem Ever
- LINUX下常用SHELL指令
- React Navigation 入门(三)
- 使用Python读取C语言.so文件-: libmysqlclient.so.16: cannot open shared object file: No such file o
- nodejs express 路由
- spark-sql(二)---ThriftServer模式
- HDOJ1048 The Hardest Problem Ever
- 如何更新LMK Low Memory Killer的阈值
- IEEE论文检索地址和使用方法
- CSRF攻击与防御
- zabbix sender 配置方法
- Tomcat 部署项目的三种方法
- scala中运算符 :: 、:+ 、+: 、::: 、++ 的区别
- WCF、WebAPI、WCFREST、WebService之间的区别
- 统计APP启动时间和进入首页时间的多线程类