Csu1567:reverse Rot (water problem)

Source: Internet
Author: User

1567:reverse Rot Time limit: 1 Sec Memory Limit: MB
Submit: Solved: 82
[Submit] [Status] [Web Board] Description

A very simplistic scheme, which was used at one time to encode information, are to rotate the characters within an alphabet and rewrite them. ROT13 is the variant in which the characters A-Z is rotated places, and it's A commonly used insecure scheme that's at Tempted to "hide" data in many applications from the late 1990 's and into the early ' s.

It has been decided by Insecure Inc. to develop a product, "improves" upon this scheme by first reversing the entire s Tring and then rotating it. As an example, if we apply this scheme to string ABCD with a reversal and rotation of 1, after the reversal we would has DCBA and then after rotating this by 1 position we have the result EDCB.

Your task is to implement this encoding scheme for strings that contain only capital letters, underscores, and periods. Rotations is to be performed using the alphabet order:

Abcdefghijklmnopqrstuvwxyz_.
Note that underscore follows Z, and the period follows the underscore. Thus a forward rotation of 1 means ' a ' is shifted to ' B ', which is, ' a ' → ' B ', ' B ' → ' C ', ..., ' Z ' → ' _ ', ' _ ' → '. ', and '. ' → ' A '. Likewise a rotation of 3 means ' a ' → ' D ', ' B ' → ' E ', ... ' → ' C '.

Input

Each input line would consist of an integer N, followed by a string. N is the amount of forward rotation, such that 1≤n≤27. The string is the message to be encrypted, and would consist of 1 to characters, with the using only capital letters, underscores , and periods. The end of the input would be denoted to a final line with only the number 0.

Output

For each test case, the display the "encrypted" message, the results after being reversed and then shifted.

Sample Input
1 ABCD3 yo_there.1. DOT14 ROAD9 shifting_and_rotating_is_not_encrypting2 string_to_be_converted1 SNQZDRQDUDQ0
Sample Output
Edcbchuhkwbr. Upearoadpwrayf_lwnhaxwh. Rhpwrajax_hmwjhpwraorq. Fgvtgxpqeagdaqvaipktvureverse_rot
HINT

Source
#include <stdio.h> #include <string.h>int main () {    char  str[45],mod[]={" Abcdefghijklmnopqrstuvwxyz_. "},CH;    int n;    while (scanf ("%d", &n) >0&&n)    {        //getchar ();        scanf ("%s", str);        int Len=strlen (str);        for (int i=0,j=len-1;i<j;i++,j--)        {            ch=str[i]; str[i]=str[j];str[j]=ch;        }        for (int i=0;i<len;i++)        {for            (int j=0;j<28;j++)            if (Str[i]==mod[j])            {                if (j+n<28)                    printf ("%c", Mod[j+n]);                else                    printf ("%c", mod[j+n-28]);            }        }        printf ("\ n");}    }


Csu1567:reverse Rot (water problem)

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.