湖南多校对抗赛(2015.4.6) G
来源:互联网 发布:淘宝平面应聘 编辑:程序博客网 时间:2024/05/02 07:29
1567: Reverse Rot
Time Limit: 1 Sec Memory Limit: 128 Mb Submitted: 372 Solved: 203Description
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 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
思路:这题可以先建个数组来记录A到'.',如果加上的数小于27就直接相加,反之相加后减去28,第一次WA就是只减去了27,然后倒过来输出。
代码:
#include <map>#include <set>#include <queue>#include <vector>#include <stack>#include <cmath>#include <stdio.h>#include <stdlib.h>#include <string.h>#include <iostream>#include <algorithm>using namespace std;#define long long int ll#define ma(a) memset(a,0,sizeof(a))char d[30]={'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','_','.'};struct node{ char a; int m;}a[105];int main(){ int N; while(scanf("%d",&N)!=EOF&&N) { char c[105]; cin>>c; char e[105]; int n=strlen(c); int k=0; int z; int i; for(i=n-1;i>=0;i--) { if(c[i]=='_') { z=26; } else if(c[i]=='.') { z=27; } else z=c[i]-'A'; if(z+N>27) { z=z+N-28; } else z=z+N; e[k++]=d[z]; } for(i=0;i<k;i++) { cout<<e[i]; } cout<<endl; } return 0;}
- 湖南多校对抗赛(2015.4.6) G
- 湖南多校对抗赛(G - G)
- 湖南多校对抗赛(2015.4.6)C
- 湖南多校对抗赛(2015.4.6) A
- 湖南多校对抗赛(2015.4.6)B
- 湖南多校对抗赛(2015.4.6) E
- 湖南多校对抗赛(2015.05.10)(国防科大学校赛决赛-Semilive)G
- Aquarium Tank(csu1634+几何+二分)Contest2087 - 湖南多校对抗赛(2015.05.24)-G
- Reverse Rot Contest2073 - 湖南多校对抗赛(2015.04.06)G
- 湖南多校对抗赛(2015.4.6)CSU 1561~1569 题解
- 湖南多校对抗赛(2014.03.16) C.Pings
- Contest2071 - 湖南多校对抗赛(2015.03.28)
- Contest2073 - 湖南多校对抗赛(2015.04.06)
- Contest2073 - 湖南多校对抗赛(2015.04.06)
- 湖南多校对抗赛(2015.03.28)
- (三分)Design road,湖南多校对抗赛
- 湖南多校对抗赛(csu 1560)
- 湖南多校对抗赛(csu 1560)
- java.lang.NumberFormatException: null的解决方法
- 51nod 1393 0和1相等串(前缀和)
- 7.21 暑假集训——动态规划篇(二)
- 服务器推送技术--spring websocket + 心跳保活重连 简易聊天室demo(二)
- 一、Spring MVC起步——IntelliJ IDEA 搭建Spring MVC环境(手把手搭建)
- 湖南多校对抗赛(2015.4.6) G
- Memory split(user:kernel) config
- 为何五次方程没有求根公式?
- 神经网络与深度学习笔记——第5章 深度神经网络为何很难训练
- SEO优化
- linux命令-ps
- interesting之快捷键
- webview获取网页标题
- tcp和udp缓冲区信息