Hdu-1048-the hardest problem Ever (c + + && occasionally a water ...)

Source: Internet
Author: User
Tags strcmp

The hardest problem everTime limit:2000/1000 MS (java/others) Memory limit:65536/32768 K (java/others)
Total submission (s): 19343 Accepted Submission (s): 9061


Problem Descriptionjulius 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 is so incredibly sound, and that's 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 of the plaintext message, you shift it five places to the right to create the secure message (i.e., if the L Etter is ' A ', the cipher text would was ' F '). Since you is creating plain text out of Caesar ' s messages, you'll 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 is shifted in this cipher. Any non-alphabetical character should remain the same, and all alphabetical characters would be a upper case.

Inputinput to this problem would consist of a (Non-empty) series of up to data sets. Each data set is formatted according to the following description, and there would be no blank lines separating data s Ets. All characters would be uppercase.

A Single Data set have 3 components:

Start Line-a single line, "Start"

Cipher message-a single line containing from one to the other hundred characters, inclusive, comprising A single message from Caesar

End Line-a single line, "End"

Following the final data set would be a, "endofinput".

Outputfor each data set, there is exactly one line of output. The original message by Caesar.

Sample 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

Sample Output
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

Sourcesouth Central USA 2002
Recommendwe carefully selected several similar problems for you:1018 1032 1062 1091 1076

The meaning of the topic is very clear: is to follow the topic given the request to decrypt the string, the decryption rules are as follows:
Cipher text (original password)
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 (decipher password)
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

It is not difficult to find that characters greater than or equal to ' e ' are pushed forward by 5 characters, while characters less than or equal to ' e ' are also advancing 5 characters, but the excess part is pushed forward from ' Z ' to the front!
Also note the input format: (including multiple sets of input data) \

1.ENDINPUT means the end of the program!
2. Each set of input data starts with start and end ends.
The last code:
#include <stdio.h> #include <string.h>int main (void) {    char str[200];    int i;    while (gets (str)! = NULL && strcmp (str, "Endofinput"))    {        if (!strcmp (str, "START") | |!strcmp (str, "END") )            continue;        for (I=0;i<strlen (str); i++)        {            if (str[i]>= ' A ')            {                if (str[i]<= ' E ')                {                    str[i]= ' V ' +str[i]-' A ';                    printf ("%c", Str[i]);                }                else                {                    printf ("%c", str[i]-5);                }            }            else            {                printf ("%c", Str[i]);            }        }        printf ("\ n");    }    return 0;}



Hdu-1048-the hardest problem Ever (c + + && occasionally a water ...)

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.