Poj1298_The Hardest Problem Ever(水题)

来源:互联网 发布:淘宝上怎么找卖bt种子 编辑:程序博客网 时间:2024/05/19 16:23

一、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
  1. Start line - A single line, "START"
  2. Cipher message - A single line containing from one to two hundred characters, inclusive, comprising a single message from Caesar
  3. 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.
二、问题分析
        最近两天,哥们被三伏天折磨的想死的心都有了。于是乎,我决定找几道水题来降降温。这道号称是“史上最难的问题”的题目就是一道标准的水题。
        题目很简单,密码转译问题。开始的时候以为是加密,这也算是我所唯一检查了的地方。用字符串存放输入,然后把字符串转换为字符数组。把字母分为两部分,A~F字符转换为Ascii码后加21,G~Z转换为AscII后减5。遍历每个字符,按上面的规则改变字母。
        刚刚看到网友爆料,此题居然和3749一样。我还以为是和它一样水呢,没想到是一样的题,不过3749是中文的。哎呀,还省了翻译的时间,要知道水题最难之处就是翻译啊!!!
三、Java代码
     
import java.io.BufferedReader;import java.io.IOException;import java.io.InputStreamReader;public class Main {public static void main(String[] args) throws IOException {BufferedReader read=new BufferedReader(new InputStreamReader(System.in));while(!read.readLine().equals("ENDOFINPUT")){String s=read.readLine();char[] c=s.toCharArray();for(int i=0;i<c.length;i++){    int a=(int)c[i];    if(a>= 70 && a<=90){    c[i]=(char) (c[i]-5);    }else if(a>=65 && a<=69){    c[i]=(char) (c[i]+21);    }}System.out.println(c);read.readLine();}}}



原创粉丝点击