#C7144. Rotate String
Rotate String
Rotate String
You are given a string s
and a non-negative integer k
. Your task is to rotate the string to the right by k
positions.
The rotation is defined as moving the last k
characters of the string to the front. Formally, if the length of the string is n, then the rotated string is given by:
$$ \text{result} = s[(n - (k \mod n)):] + s[:(n - (k \mod n))] $$
For example, if s = "abcdef"
and k = 2
, the rotated string is "efabcd"
.
inputFormat
The input consists of two lines:
- The first line contains the string
s
. - The second line contains the non-negative integer
k
.
outputFormat
Output a single line containing the rotated string.
## sampleabcdef
2
efabcd