SDUT 3189 Reverse Rot(水题)

Reverse Rot

Time Limit: 1000MS Memory limit: 65536K

题目描述

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\‘.

输入

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.

输出

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

示例输入

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

示例输出

EDCB
CHUHKWBR.
UPEA
ROAD
PWRAYF_LWNHAXWH.RHPWRAJAX_HMWJHPWRAORQ.
FGVTGXPQEAGDAQVAIPKTVU
REVERSE_ROT

提示

来源

2014 ACM MId-Central Reginal Programming Contest(MCPC2014)

示例程序

#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 0x3f3f3f3f

using 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 == 27)
                {
                    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;
}
时间: 2024-09-30 04:36:34

SDUT 3189 Reverse Rot(水题)的相关文章

sdut 2841 Bit Problem (水题)

题目 贴这个题是因为看题解有更简单的方法, 我做的时候是直接算的, 也很简单. 贴一下题解吧: 如果一个整数不等于 0,那么该整数的二进制表示中至少有一位是 1. 这个题结果可以直接输出 x - (x&(x-1)); 因为x-1 之后二进制下,就是最右边的1变成了0, 最右边的1的 右边所有的0变成了1, 不影响最左边. 我的代码: 1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4

HDU 1062 Text Reverse(水题,字符串处理)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1062 解题报告:注意一行的末尾可能是空格,还有记得getchar()吃回车符. 1 #include<cstdio> 2 #include<string.h> 3 #include<iostream> 4 #include<algorithm> 5 #include<cmath> 6 #include<deque> 7 #include&

合天实验室,挑战练习。 reverse水题

关于reverse的水题.基础的. 题目链接:http://erange.heetian.com/CTFrace.html [1,dex2jar好用] 说是dex2jar好用,就猜到是apk了.改zip,解压出classes.de之后,用dex2jar,再用jd打开. 发现这么一段奇怪的字符数字,直接改成char表示,得到flag. f l a g { w 4 n n 4 _ j 4 r _ m y _ d 3 x } 去掉空格输入进去.ok. [2. int 3 断点稍微有点绕:pw1_pw2

CSU1567: Reverse Rot(水题)

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 r

sdut 2413:n a^o7 !(第三届山东省省赛原题,水题,字符串处理)

n a^o7 ! Time Limit: 1000MS Memory limit: 65536K 题目描述 All brave and intelligent fighters, next you will step into a distinctive battleground which is full of sweet and happiness. If you want to win the battle, you must do warm-up according to my inst

SDUT 2829-家快来A水题(邻接矩阵)

家快来A水题 Time Limit: 4000ms   Memory limit: 65536K  有疑问?点这里^_^ 题目描述 给出一个无向无权图,有n(1<= n <= 1000)个点,m(1<= m <= 1000000)条边.点的编号从1到n.m条边中可能会有重复的边,问去掉重复的边之后还剩下多少条边. 输入 多组输入.每组输入的第一行包括两个整数n,m.接下来的m行,每行包含两个整数u,v,表示两点之间有一条边. 输出 输出一个整数代表答案. 示例输入 2 3 1 2

codeforces Gym 100187L L. Ministry of Truth 水题

L. Ministry of Truth Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100187/problem/K Description Andrey works in the Ministry of Truth. His work is changing articles in newspapers and magazines so that they praise the Party an

POJ百道水题列表

以下是poj百道水题,新手可以考虑从这里刷起 搜索1002 Fire Net1004 Anagrams by Stack1005 Jugs1008 Gnome Tetravex1091 Knight Moves1101 Gamblers1204 Additive equations 1221 Risk1230 Legendary Pokemon1249 Pushing Boxes 1364 Machine Schedule1368 BOAT1406 Jungle Roads1411 Annive

poj-3481-Double Queue-splay树的水题

很水的splay树. 会简单的操作即可... #include<stdio.h> #include<string.h> #include<algorithm> #include<iostream> #include<vector> using namespace std; #define maxn 1100000 #define mem(a,b) memset(a,b,sizeof(a)) #define root10 ch[ch[root][1