CPP
cpp
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
#include <iostream>
using namespace std;
int code(char c) {
return c - 'A';
}
string expand(const string& str, int n) {
string current_word = str;
int hash;
int iter = 0;
int i = 1;
string text = "";
bool first = true;
while (iter < n) {
if (first) {
text += current_word[i-1];
first = false;
}
hash = code(current_word[i-1]) + code(current_word[i]);
int position = (hash) % 26; // position where I need to find the char to be inserted
string c = string(1, 'A' + position); // Get a string representation of this char
text += c;
text += current_word[i];
i++;
if (i >= current_word.size()) {
Enter to Rename, Shift+Enter to Preview
OUTPUT
Run