zoukankan      html  css  js  c++  java
  • Poj1298_The Hardest Problem Ever(水题)

    一、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();
    		}
    	}
    }
    



    版权声明:本文为博主原创文章,未经博主允许不得转载。

  • 相关阅读:
    java.lang.IllegalStateException: Cannot get a STRING value from a NUMERIC cell
    spring boot 启动报:Composite-id class must implement Serializable: xxx错误
    IntelliJ IDEA 中使用region代码折叠
    JSON parse error: Cannot deserialize value of type `java.time.LocalDateTime` from String
    MySQL生成UUID
    PowerDesigner设计表时显示注释列Comment,Columns中没有Comment的解决办法
    使用PowerDesigner创建物理模型并生成SQL语句在MySQL中生成表
    IMP-00003: 遇到 ORACLE 错误 959 ORA-00959: 表空间 '' 不存在
    SP2-0734: 未知的命令开头 “IMP ”
    使用imp命令和exp命令对oracle数据库进行导入导出操作
  • 原文地址:https://www.cnblogs.com/AndyDai/p/4734206.html
Copyright © 2011-2022 走看看