WBC '25 P1 - Secret Message

View as PDF

Submit solution

Points: 3
Time limit: 1.0s
Memory limit: 256M

Author:
Problem type
Welcome 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 S and a number k, they encrypt S by doing the following process:

  • Take all the letters up to (and including) the k-th letter of string S and call this string A
  • Take all the letters after the k-th letter of string S and call this string B
  • Reverse both strings A and B
  • Join the new strings A and B to form AB (the encrypted message)

For example, if the message S = abcdefg and k=3, 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 N (1 \le N \le 10), the number of characters in Barry's message.

The second line contains the integer k \, (1 \le k \le N).

The third line contains the string S.

The string S will never exceed a length of 10 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 A is just c.

The second string B is abcd.

Reversing strings A and B 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 A is abc.

The second string B is (an empty string).

Reversing strings A and B gives cba and .

The new encrypted string is created by joining the two strings, which is cba.


Comments

There are no comments at the moment.