HDU1048, 1048 phantom room

Source: Internet
Author: User

HDU1048, 1048 phantom room
Problem DescriptionJulius Caesar lived in a time of danger and intrigger. the hardest situation Caesar ever faced was keeping himself alive. in order for him to keep ve, he decided to create one of the first ciphers. this cipher was so incredibly sound, that no one cocould 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 wocould 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 shoshould remain the same, and all alphabetical characters will be upper case.

 

InputInput 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, sive Sive, comprising a single message from Caesar

End line-A single line, "END"

Following the final data set will be a single line, "ENDOFINPUT ".

 

OutputFor each data set, there will be exactly one line of output. This is the original message by Caesar.

 

Sample InputSTARTNS BFW, hybrid TK hybrid fwj ymj hybrid TK hybrid BTZQI hybrid gj knwxy ns f hybrid ngjwnfs anqqflj ymfs hybrid NS hybrid pstbx kzqq bjqq ymfy hfjxfw rtwj hybrid YMFS Hybrid

 

Sample OutputIN WAR, events of importance are the result of trivial causesi wocould RATHER BE FIRST IN A LITTLE IBERIAN VILLAGE THAN SECOND IN ROMEDANGER KNOWS FULL WELL THAT CAESAR IS MORE DANGEROUS THAN HE
1 # include "stdio. h "2 # include" string. h "3 int main (void) 4 {5 char fr [10] =" START ", end [10] =" END ", main [1000]; 6 int len, i; 7 while (scanf ("% s", fr )! = EOF & strcmp (fr, "ENDOFINPUT ")! = 0) 8 {9 getchar (); // input segment 10 gets (main); 11 scanf ("% s", end); 12 13 len = strlen (main ); // processing segment 14 for (I = 0; I <len; I ++) 15 {16 if (main [I]> 'Z' | main [I] <'A') continue; 17 if (main [I]> 'E ') main [I] = main [I]-5; 18 else main [I] = 'Z'-(5-main [I] + 'A') + 1; 19} 20 for (I = 0; I <len; I ++) // output segment, puts () should also be 21 printf ("% c ", main [I]); 22 printf ("\ n"); 23} 24 return 0; 25}

 

 

I have been writing this code for two hours. Don't laugh at me (unhappy). The first algorithm is completely wrong, because I ignored "END" in my thinking, it is troublesome to find out, and the syntax for puts () and % s is not clear about the line feed. C is just a language, however, when other languages are entangled in line breaks, I think I should pay attention to it in the future.

In the use of character groups, especially the length of character groups, must be slightly greater than the required length, and pay attention to the processing of the '\ 0' terminator (this is the most annoying ).

I will not elaborate on the idea of solving 1048 of the problems. It is really a water question. Let's look at the code.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.