WBC '25 P1 - Secret Message
View as PDFWelcome Back Contest: 2025 Problem 1
Barry is a secret FBI agent and needs to send secret messages with other agents. The agents have been experimenting with a new encryption method, where given a string and a number
, they encrypt
by doing the following process:
- Take all the letters up to (and including) the
-th letter of string
and call this string
- Take all the letters after the
-th letter of string
and call this string
- Reverse both strings
and
- Join the new strings
and
to form
(the encrypted message)
For example, if the message =
abcdefg and , we first split
abcdefg into abc and defg. Then, we reverse both strings to get cba and gfed. Finally, we join them to get our encrypted string cbagfed.
Barry would like to send a message to another agent and needs your help to encrypt it!
Input Specification
The first line contains the integer
, the number of characters in Barry's message.
The second line contains the integer .
The third line contains the string .
The string will never exceed a length of
and each character will be a lowercase letter from
a-z inclusive.
Output Specification
Output the new encrypted string on a single line.
Sample Input 1
7
3
abcdefg
Output for Sample Input 1
cbagfed
Explanation of Output for Sample Input 1
This is the same case as the example.
Sample Input 2
5
1
cabcd
Output for Sample Input 2
cdcba
Explanation of Output for Sample Input 2
The first string is just
c.
The second string is
abcd.
Reversing strings and
gives
c and dcba.
The new encrypted string is created by joining the two strings, which is cdcba.
Sample Input 3
3
3
abc
Output for Sample Input 3
cba
Explanation of Output for Sample Input 3
The first string is
abc.
The second string is
(an empty string).
Reversing strings and
gives
cba and .
The new encrypted string is created by joining the two strings, which is cba.
Comments