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



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

  • 相关阅读:
    D365FO Debug找不到w3cp进程
    D365FO 10.0PU32 开发环境 Data Management导出失败
    一张图看懂项目管理
    用户体验为什么重要?如何提升产品的用户体验?(写给产品小白)
    敏捷考证?你应该知道的敏捷体系认证(最全名单)
    漫画:禅道程序员的一天
    敏捷开发管理--任务分解经验之谈
    漫画:优秀程序员的必备特质有哪些?
    漫画:女生/男生告白攻略
    漫画:程序员脱单秘籍
  • 原文地址:https://www.cnblogs.com/AndyDai/p/4734207.html
Copyright © 2011-2022 走看看