凉脾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

Sample Output 1

EWPGAJRB

ABCD

Sample Input 2

Sample Output 2

UEQBJPJCBUDGBNKCAHXCVERXUCVK

ACMECNACONTEST

思路:把字符串从中间分成两段,左右分别计算偏移值之和,算出处理后的字串每个字符相对于A的偏移值,字符都加上对应的偏移值。

#include <iostream>
#include <bits/stdc++.h>
const int N = 15000;
using namespace std;

int main(){
	char arr[N],b[N],c[N],d[N];
	cin >> arr;
	int sum1=0,sum2=0;
	int x = strlen(arr);
	
	//求和 
	for(int i=0; i<x/2; i++)
		sum1 += (arr[i] - 65);
	for(int i=x/2; i<x; i++)
		sum2 += (arr[i] - 65);
		
	//旋转 
	for(int i=0; i<x/2; i++)
		b[i] = ((arr[i] - 65) + sum1)%26;
	for(int i=x/2; i<x; i++)
		c[i - x/2] = ((arr[i] - 65) + sum2)%26;
	//合并 
	for(int i=0; i<x/2; i++)
		b[i] = (b[i] + c[i])%26;
		
	for(int i=0; i<x/2; i++)
		d[i] += (b[i]+65);
	cout << d << endl;
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值