Shift Letters
InterviewTime limit1sMemory limit128 MB
For each test case, rotate the letters of a word right by n positions and print the result in a fixed sentence format.
- Level
Easy2 of 10
- Topics
- String, Implementation, Simulation
- Solved
- No attempts yet
Problem
Bilbo wants to send a message to the dwarves, who are currently being held prisoner by the Great Goblin. He has a way to get it to them, but there is a chance the orcs may intercept the message. So he decides to encrypt it using a very simple scheme (enough to fool the orcs, who are not known for their intelligence).
Specifically, he shifts the letters of every word in the message to the right by a small amount, wrapping the overflow around to the front. For example, shifting "oakenshield" by 3 gives "eldoakenshi", whereas shifting "gandalf" by 2 gives "lfganda". He shifts every word by a different number of letters, always less than the number of letters in that word.
Write a program to help Bilbo encode his message.
Input
The first line contains the number of test cases (). Each of the following lines contains one test case: a word (a string) followed by an integer . You may assume that .
Output
For each test case, output a single line containing the word formed by shifting every letter of to the right by and wrapping around to the front. Use exactly the following format:
Shifting w by n positions gives us: result
where w is the original word, n is the shift amount, and result is the shifted word.