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

凉脾的比赛

时间:2020-01-22 20:06:36      阅读:61      评论:0      收藏:0      [点我收藏+]

标签:比赛   tab   http   blank   NPU   ble   divide   ram   min   

A - DRM Messages

DRM Encryption is a new kind of encryption. Given an encrypted string (which we’ll call a DRM message), the decryption process involves three steps: Divide, Rotate and Merge. This process is described in the following example with the DRM message “EWPGAJRB”:

Divide

– First, divide the message in half to “EWPG” and “AJRB”.

Rotate

– For each half, calculate its rotation value by summing up the values of each character (A=0,B=1,,Z=25A=0,B=1,…,Z=25). The rotation value of “EWPG” is 4+22+15+6=474+22+15+6=47. Rotate each character in “EWPG” 4747 positions forward (wrapping from Z to A when necessary) to obtain the new string “ZRKB”. Following the same process on “AJRB” results in “BKSC”.

Merge

– The last step is to combine these new strings (“ZRKB” and “BKSC”) by rotating each character in the first string by the value of the corresponding character in the second string. For the first position, rotating ‘Z’ by ‘B’ means moving it forward 1 character, which wraps it around to ‘A’. Continuing this process for every character results in the final decrypted message, “ABCD”.

Input

The input contains a single DRM message to be decrypted. All characters in the string are uppercase letters and the string’s length is even and 15000≤15000.

Output

Display the decrypted DRM message.

Sample Input 1Sample Output 1
EWPGAJRB
ABCD
Sample Input 2Sample Output 2
UEQBJPJCBUDGBNKCAHXCVERXUCVK
ACMECNACONTEST

 

思路:
  模拟,比赛的时候找了半天的bug,没想到是把i写成l了!!!

 1 #include <iostream>
 2 #include <algorithm>
 3 #include <cstdio>
 4 #include <string>
 5 using namespace std;
 6 int main()
 7 {
 8     string s;
 9     int a[15005];
10     int s1=0,s2=0;
11     cin>>s;
12     int l=s.size();
13     for(int i=0;i<l;i++)
14     {
15         a[i]=s[i]-A;    
16     }
17     for(int i=0;i<l/2;i++)
18     {
19         s1+=a[i];
20     }
21     for(int i=l/2;i<l;i++)
22     {
23         s2+=a[i];
24     }
25     s1%=26;
26     s2%=26;
27     for(int i=0;i<l/2;i++)
28     {
29         a[i]+=s1;
30         a[i]%=26;
31     }
32     for(int i=l/2;i<l;i++)
33     {
34         a[i]+=s2;
35         a[i]%=26;
36     }
37     for(int i=0;i<l/2;i++)
38     {
39         a[i]+=a[i+l/2];
40         a[i]%=26;
41         cout<<char(a[i]+A);
42     }
43     
44     
45 
46     
47 }

凉脾的比赛

标签:比赛   tab   http   blank   NPU   ble   divide   ram   min   

原文地址:https://www.cnblogs.com/wsytj/p/12229352.html

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