#C660. Alphabet Shift
Alphabet Shift
Alphabet Shift
You are given a string s
consisting of lowercase English letters and an integer n
. Your task is to shift every character in the string s
by n
positions forward in the alphabet. Note that the alphabet wraps around, so after 'z'
comes 'a'
.
The new character for each letter ch
is determined by the formula:
$$ new\_char = ((ord(ch) - ord('a') + n) \mod 26) + ord('a') $$
For example, shifting 'a'
by 2 positions results in 'c'
and shifting 'z'
by 1 position wraps around to 'a'
.
inputFormat
The input is read from standard input (stdin). It consists of two values:
- A string
s
containing only lowercase letters. - An integer
n
on the same line or the next line which denotes the number of positions to shift each character.
The values are separated by whitespace or newline.
outputFormat
The output should be written to standard output (stdout). It is a single string after shifting each character by n
positions in the alphabet.
abc
2
cde