#C2223. Taco's Alphabet Shift

    ID: 45516 Type: Default 1000ms 256MiB

Taco's Alphabet Shift

Taco's Alphabet Shift

You are given a string s consisting of lowercase alphabets and an integer k. Your task is to transform the string by shifting every character by k positions in the alphabet. The transformation should wrap around the alphabet if necessary. For example, shifting 'z' by 1 results in 'a'.

The transformation for each character c can be mathematically described using the following formula:

$$ c' = \left(\big(\mathrm{ord}(c) - \mathrm{ord}(\mathtt{'a'}) + k\big) \mod 26\right) + \mathrm{ord}(\mathtt{'a'}) $$

where \(\mathrm{ord}(c)\) gives the ASCII value of the character c. The final result is obtained by converting the calculated ASCII value back to its corresponding character.

Example

  • For s = "abc" and k = 2, the output is "cde".
  • For s = "hello" and k = 1, the output is "ifmmp".

inputFormat

The input is read from standard input (stdin) and consists of two lines. The first line is a non-empty string s containing only lowercase alphabets. The second line is an integer k representing the number of positions by which to shift each character.

outputFormat

Output the transformed string to standard output (stdout) after shifting each character by k positions in the alphabet with wraparound.## sample

abc
2
cde