-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path2022-BIO-1.cpp
More file actions
35 lines (30 loc) · 813 Bytes
/
2022-BIO-1.cpp
File metadata and controls
35 lines (30 loc) · 813 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
#include <bits/stdc++.h>
using namespace std;
int main() {
// First - 17min
string word;
std::cin >> word;
int wordSize = word.size();
int letters [wordSize];
// Replace w/ number
for (int i = 0; i < wordSize; i++) {
letters[i] = int(word[i]) - 64; // From 1
}
// Not first letter - decrypt backwards
for (int i = wordSize-1; i > 0; i--) {
letters[i] -= letters[i-1];
// Handle out-of-range
if(letters[i] < 1) {
letters[i] += 26;
}
}
// Replace w/ letter - could only save next letter
for (int i = 0; i < wordSize; i++) {
word[i] = char(letters[i] + 64); // From 1
}
for (int letter: letters) {
std::cout << letter << " ";
}
std::cout << "\n";
std::cout << word;
}