Sdut 3189 Reverse Rot (water problem)

Source: Internet
Author: User

Reverse Rot Time limit:1000ms Memory limit:65536k Title 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 2000\ ' 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 And then after rotating this by DCBA 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\ ' .InputEach input line would consist of an integer N, followed by a string. N is the amount of forward rotation, such. 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.Outputfor 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 ACM mid-central reginal programming Contest (MCPC2014) sample program

#include <iostream> #include <algorithm> #include <stdio.h> #include <string.h> #include < stdlib.h> #include <queue> #include <stack> #include <vector> #include <math.h> #include <        Map> #define INF 0x3f3f3f3fusing namespace Std;char a[101];int n;int main () {while (scanf ("%d", &n)!=eof) {        if (n = = 0) {break;        } scanf ("%s", a);        int len = strlen (a);        n = n%28;            for (int i=len-1;i>=0;i--) {if (a[i] = = '. ')                {if (n = =) {printf ("_");                } else {printf ("%c", ' A ' +n-1);            } continue;                } if (a[i] = = ' _ ') {if (n = = 1) {printf (".");                } else {printf ("%c", ' A ' +n-2);      }          Continue } if (a[i]+n> ' z ') {if (a[i]+n-' z ' = = 1) {printf (                "_");                } else if (a[i]+n-' Z ' = = 2) {printf (".");                } else {printf ("%c", ' A ' +a[i]+n-' Z '-3);            }} else {printf ("%c", a[i]+n);    }} printf ("\ n"); } return 0;}


Sdut 3189 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.