TORONTO KIDS COMPUTER CLUB | PMCA Sunday 12:00 Java Homework 20.01.19.
16972
post-template-default,single,single-post,postid-16972,single-format-standard,ajax_fade,page_not_loaded,,qode-theme-ver-7.6.2,wpb-js-composer js-comp-ver-6.8.0,vc_responsive

PMCA Sunday 12:00 Java Homework 20.01.19.

23 Jan PMCA Sunday 12:00 Java Homework 20.01.19.

Problem Description
Ken is working for the secret agency. He is going to send a secret message that encodes UPPERCASE words by shifting their letters forward.

Shifting a letter by S positions means to go forward S letters in the alphabet. For example, shifting B by S = 3 positions gives E. However, sometimes this makes us go past Z, the last letter of the alphabet. Whenever this happens we wrap around, treating A as the letter that follows Z. For example, shifting Z by S = 2 positions gives B.

Ken’s code depends on a parameter K and also varies depending on the position of each letter in the word. For the letter at position P, they use the shift value of S = 2*K+3*P.

For example, here is how “FIND” is encoded when K = 3. The first letter F has a shift value of S = 2 × 3 + 3 × 1 = 9; it wraps around and becomes the letter O. The second letter, I, has S = 2 × 3 + 3 × 2 = 12 and becomes U. The last two letters become C and V. So Ken sends the secret message: OUCV

Write a program to encode messages sent by Ken.

Input Specification
The input will be two lines. The first line will contain the positive integer K (K < 10), which is used to compute the shift value. The second line of input will be the original word, which will be a sequence of uppercase characters of length at most 20.

Output Specification
The output will be the encoded word of uppercase letters.

Sample Input 1
3
FIND

Output for Sample Input 1
OUCV

Sample Input 2
5
MISSILE

Output for Sample Input 2
ZYLOHNJ

No Comments

Sorry, the comment form is closed at this time.