Editorial for Lady of the Lake
Remember to use this editorial only when stuck, and not to copy-paste code from it. Please be respectful to the problem author and editorialist.
Submitting an official solution before solving the problem yourself is a bannable offence.
Submitting an official solution before solving the problem yourself is a bannable offence.
Authors:
An easy way to find the correct shift amount and resultant letter is to assign each letter of the alphabet a number that increments each time. There are several ways to do this. After that, the resultant letter is (current + absolute_value(current - previous)) mod 26
assuming a
is 0
, b
is 1
and so on. Keep in mind that the first character in the input may be a space.
Pseudo Code
char previousLetter = '0';
for (char current : allCharacters) {
if (current == ' ') print(' ');
else {
if (previousLetter == '0') print(current);
else {
char newLetter = (current - 'a' + Math.abs(current - previousLetter)) % 26;
print(newLetter);
}
previousLetter = current;
}
}
Comments