HDU 1048 JAVA

原创 2017年05月12日 13:22:33

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

package hlh;

import java.util.Scanner;

public class p1048 {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while(sc.hasNext()){
            String str = sc.nextLine();
            //卫条件过滤
            if(str.equals("ENDOFINPUT")){
                break;
            }
            if(str.equals("START")){
                continue;
            }
            if(str.equals("END")){
                continue;
            }
            char s [] = str.toCharArray();
            for(int i=0;i<s.length;i++){
                // 判读是否为需要转换的字母
                if((int)s[i]>64&&(int)s[i]<91){
                    // 密文转换回原文
                    int j = (int)s[i]-5;
                    if(j<65){
                        j=j+26;
                    }
                    s[i]=(char) j;
                }
                System.out.print(s[i]);
            }
            System.out.println();
        }
    }

}
版权声明:本文为博主原创文章,大家一起学习进步。

【动态规划】求最大上升子序列

问题描述 一个数的序列bi,当b1 < b2 < … < bS的时候,我们称这个序列是上升的。对于给定的一个序列(a1, a2, …, aN),我们可以得到一些上升的子序列(ai1, ai2, …,...

【MOOC】【枚举】a.特殊密码锁——位运算

总时间限制: 1000ms 内存限制: 1024kB 描述 有一种特殊的二进制密码锁,由n个相连的按钮组成(n...

HDU1048

1048The Hardest Problem Ever Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K ...
  • lx0208
  • lx0208
  • 2017年07月24日 15:01
  • 106

HDU 1048 The Hardest Problem Ever

Problem Description Julius Caesar lived in a time of danger and intrigue. The hardest situation C...

HDU 1048 The Hardest Problem Ever(字符串处理)

题目链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=1048The Hardest Problem EverTime Limit: 2000/10...

HDU 1048字符串格式控制

The Hardest Problem Ever Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K ...
  • w_linux
  • w_linux
  • 2017年07月30日 22:05
  • 92

HDU 1048

HDU 1048The Hardest Problem EverTime Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 ...

hdu_1048_The Hardest Problem Ever_字符输入输出问题水题一道

字符输入输出问题很水很水. http://acm.hdu.edu.cn/showproblem.php?pid=1048 The Hardest Problem Ever Tim...

hdu1048 The Hardest Problem Ever

The Hardest Problem Ever Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Jav...

HDU 1048.The Hardest Problem Ever【字符串处理】【8月25】

The Hardest Problem Ever Problem Description Julius Caesar lived in a time of danger and int...
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:HDU 1048 JAVA
举报原因:
原因补充:

(最多只允许输入30个字)