码迷,mamicode.com
首页 > 其他好文 > 详细

CSU1567: Reverse Rot(水题)

时间:2015-04-06 20:21:02      阅读:186      评论:0      收藏:0      [点我收藏+]

标签:

1567: Reverse Rot

Time Limit: 1 Sec  Memory Limit: 128 MB
Submit: 150  Solved: 82
[Submit][Status][Web Board]

Description

A very simplistic scheme, which was used at one time to encode information, is to rotate the characters within an alphabet and rewrite them. ROT13 is the variant in which the characters A-Z are rotated 13 places, and it was a commonly used insecure scheme that attempted 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 that "improves" upon this scheme by first reversing the entire string 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 have DCBA and then after rotating that 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 are 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‘, that is, ‘A‘→‘B‘, ‘B‘→‘C‘, ..., ‘Z‘→‘_‘, ‘_‘→‘.‘, and ‘.‘→‘A‘. Likewise a rotation of 3 means ‘A‘→‘D‘, ‘B‘→‘E‘, ..., ‘.‘→‘C‘.

Input

Each input line will 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 will consist of 1 to 40 characters, using only capital letters, underscores, and periods. The end of the input will be denoted by a final line with only the number 0.

Output

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

Sample Input

1 ABCD
3 YO_THERE.
1 .DOT
14 ROAD
9 SHIFTING_AND_ROTATING_IS_NOT_ENCRYPTING
2 STRING_TO_BE_CONVERTED
1 SNQZDRQDUDQ
0

Sample Output

EDCB
CHUHKWBR.
UPEA
ROAD
PWRAYF_LWNHAXWH.RHPWRAJAX_HMWJHPWRAORQ.
FGVTGXPQEAGDAQVAIPKTVU
REVERSE_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(水题)

标签:

原文地址:http://blog.csdn.net/u010372095/article/details/44904357

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!