-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathDRMMessages.cpp
More file actions
49 lines (36 loc) · 836 Bytes
/
DRMMessages.cpp
File metadata and controls
49 lines (36 loc) · 836 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#include <iostream>
#include <string>
#include <utility>
using namespace std;
string rotate(string toRotate)
{
int sum = 0;
for(size_t i = 0; i < toRotate.size(); i++)
{
sum += toupper(toRotate[i]) - 'A';
}
for(size_t i = 0; i < toRotate.size(); i++)
{
toRotate[i] = ((toRotate[i] - 'A' + sum) % 26) + 'A';
}
return toRotate;
}
int main()
{
string input;
cin >> input;
// divide
string firstHalf = input.substr(0, input.size() / 2);
string secondHalf = input.substr(input.size() / 2);
// rotate
string rotatedFirstHalf = rotate(firstHalf);
string rotatedSecondHalf = rotate(secondHalf);
// merge
string output = "";
for(size_t i = 0; i < rotatedFirstHalf.size(); i++)
{
output += char(((rotatedFirstHalf[i] - 'A' + rotatedSecondHalf[i] - 'A') % 26) + 'A');
}
cout << output << endl;
return 0;
}