Canadian Computing Competition: 2012 Stage 1, Junior #4
Sheldon and Leonard are physicists who are fixated on the BIG BANG theory. In order to exchange secret insights, they have devised a code that encodes UPPERCASE words by shifting their letters forward.
Shifting a letter by B
by 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 B
.
Sheldon and Leonard's code depends on a parameter
For example, here is how ZOOM
is encoded when Z
has a shift value of F
. The second letter, O
, has X
. The last two letters become A
and B
. So Sheldon sends Leonard the secret message: FXAB
Write a program for Leonard that will decode messages sent by Sheldon.
Input Specification
The input will be two lines. The first line will contain the positive integer
Output Specification
The output will be the decoded word of uppercase letters.
Sample Input 1
3
FXAB
Output for Sample Input 1
ZOOM
Sample Input 2
5
JTUSUKG
Output for Sample Input 2
BIGBANG
Comments
Taking
also works.
Looking for a little help…in the second sample…first letter, s=5*1+5=10. If you move 10 spots to the left of j, you get z. The shift s should be 8. What am I missing? Thanks.
Shift is
, where position 
of 1st letter 'B' is 1. So shift is 
. Therefore J becomes B after left shift.
Thank you
How do the sample outputs work? When I put 3 and FXAB, and do this formula 3×1+3, how does it go to Z? My program got LGMQ, because when you add the 6 to F (at pos 6) you get to 12 which is L?
The question asks you to decode a message, not encode a message.
Is it just my inexperience, or do you have to use a separate
if else
loop for every separate letter?bruh make the word decode 10 times bigger
My submission produced an AC result. But after I tested it with the following input
It gave the following output:
How come?
It is possible for the ASCII character code after decoding to be less than 39. Simply adding 26 to the result will not always make it into a valid letter—sometimes you will need to add a multiple of 26.