Description: Julius Caesar lives in times of danger and intrigue. In order to survive, he invented the password for the first time for the army's message delivery. Suppose you are an officer in the Caesar Corps who needs to decipher the message sent by Caesar and provide it to your general. Message encryption means that each letter in the original message is replaced with the 5th letter of the letter (for example: Each letter A in the original message is replaced with the letter F), the other characters are unchanged, and all the letters in the original message are capitalized. Password Letter: 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 Original letter: 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
Input: Up to 100 datasets. Each dataset consists of 3 parts: Start line: Start password message: A line consisting of 1 to 200 characters representing the end line of a message issued by Caesar: End after the last dataset, is another line: Endofinput
Output: One row for each dataset, which is the original message for Caesar.
Input
Startns BFW, Jajsyx tk nrutwyfshj fwj ymj wjxzqy tk ywnanfq hfzxjxendstartn btzqi wfymjw GJ knwxy NS F qnyyqj NGJWNFS ANQQ Flj Ymfs xjhtsi NS wtrjendstartifsljw pstbx kzqq bjqq ymfy hfjxfw NX rtwj ifsljwtzx Ymfs mjendendofinput
Ouput:
In WAR, EVENTS of importance is the RESULT of TRIVIAL Causesi would rather be first in A LITTLE Iberian VILLAGE THAN SECO ND in Romedanger KNOWS full well, CAESAR is more dangerous THAN HE
Analysis: The topic is relatively simple, need to pay attention to the use of input functions, password message contains spaces, it is not possible to use CIN input, so use Getline (CIN.STR) input, especially the first start of the string to use the Getline () input, otherwise the password essay is blank, I think it should be. Enter start with a carriage return after the carriage return is also in the buffer, wait until the input with getline () is read to enter the end of the input, so that the password message is blank.
Getline (), with carriage return as the Terminator only
1#include <iostream>2#include <string>3 using namespacestd;4 5 voidChangestring&a)6 {7 for(inti =0; I < a.size (); i++)8 {9 if(A[i] >='A'&&a[i] <='U')TenA[i] + =5; One Else if(A[i] >='V'&&a[i] <='Z') AA[i] ='A'+ A[i]-'V'; - } - } the - intMain () - { - stringstart, message, end; + while(Getline (CIN, start)) && (Start.compare ("Endofinput"))) - { + getline (cin,message); A getline (CIN, end); at Change (message); -cout << Message <<Endl; - } -System"Pause"); - return 0; -}
Fun question: Caesar Caesar Password (c + + implementation)