CSU1567 Reverse Rot
来源:互联网 发布:网络键盘侠 编辑:程序博客网 时间:2024/05/22 06:05
Reverse Rot
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 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
———————————————————————————
#include <iostream>#include <cstdio>#include <algorithm>#include <cmath>#include <cstring>#include <string>#include <queue>#include <stack>#include <set>#include <map>using namespace std;#define LL long longconst LL mod=1e9+7;const int INF=0x3f3f3f3f;#define MAXN 100005char s[100005];int n;char a[30]="ABCDEFGHIJKLMNOPQRSTUVWXYZ_.";int b[100005];int main(){ while(~scanf("%d",&n)&&n) { scanf("%s",s); int k=strlen(s); for(int i=0; i<k/2; i++) { swap(s[i],s[k-i-1]); } for(int i=0; i<k; i++) { if(s[i]=='_') b[i]=26; else if(s[i]=='.') b[i]=27; else b[i]=s[i]-'A'; b[i]+=n; if(b[i]>27) b[i]-=28; } for(int i=0;i<k;i++) printf("%c",a[b[i]]); printf("\n"); } return 0;}
- CSU1567:Reverse Rot(DFS)
- CSU1567 Reverse Rot
- CSU1567-Reverse Rot
- CSU1567: Reverse Rot(水题)
- csu 1567: Reverse Rot
- CSU-1567-Reverse Rot
- CSU 1567Reverse Rot
- csu 1567 Reverse Rot
- CSU 1567 Reverse Rot
- SDUT 3189 Reverse Rot(水题)
- Reverse Rot Contest2073 - 湖南多校对抗赛(2015.04.06)G
- ROT-13
- ROT-13
- Link Rot检测
- 学习BLAS库 -- ROT
- base64和rot-13
- 短语the rot set in
- What's ROT? Running object table!
- 百度API学习笔记1
- odoo10 基本参数
- Java定时任务调度之Quartz
- l链表操作(合并两个有序链表为一个新链表)
- odoo10基本方法
- CSU1567 Reverse Rot
- numpy Array [: ,] 的取值方法
- SpringMVC框架解析
- Python3 多线程
- 利用qwtplot3d绘制3维图形
- Java 网络IO编程总结(BIO、NIO、AIO)
- SQL优化(索引)
- UVA 1586
- Java源码阅读-HashMap