试机号妙用的法则(机试小课堂机试介绍周)(1)

苏世计算机考研,程序猿专属的学习分享社区

【声明:本文为原创文章,未经同意,严禁转载和抄袭,违者将追究其法律责任】

苏世机试小课堂,考研机试不再慌!

公主号:苏世学社考研 苏世计算机考研

The Hardest Problem Ever

Time Limit: 2000/1000 MS (Java/Others)

Memory Limit: 65536/32768 K (Java/Others)

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 textA B C D E F G H I J K L M N O P Q R S T U V W X Y ZPlain textV 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

答案

①读题:

这是一个英文题,直接读就行,读完发现是字符串替换问题。

②想出思路:

用一个字符数组存储“Plain text”,循环遍历原字符串中的每个字符,替换即可。

③动手编程:

试机号妙用的法则(机试小课堂机试介绍周)(2)

④测试样例:

试机号妙用的法则(机试小课堂机试介绍周)(3)

⑤提交代码:

进入下面的链接提交代码:

http://acm.hdu.edu.cn/showproblem.php?pid=1048

试机号妙用的法则(机试小课堂机试介绍周)(4)

⑥返回评测结果:

试机号妙用的法则(机试小课堂机试介绍周)(5)

至此,这道题我们就已经完成了。

本题总结

碰到英文题直接读,没必要每个单词都必须认识,可能和题目无关或者对做题没影响,有时候题目描述看着不少,但题目的意思也就一句话,比如本题就是给出替换方式,把输入的字符串挨个字符替换。这里也用到了一些字符串函数,比如strcpy()、gets()、strcmp(),判断字符的函数isalpha(),平时边做题边积累,不懂的用法就上网查,多做英文题,提高读题熟练度,也能摸索出诀窍。

未完待续

苏世学社旗下品牌,专注于计算机考研

计算机考研一手资讯,原创高质量干货

深度的学习分享丨咨询前辈丨个性化指导

试机号妙用的法则(机试小课堂机试介绍周)(6)

,