The students notice several sketchy papers on Mr. Venom's desk, each containing integers. "A code!" Tom cries. "But how do we crack it?" replies Alex. They then see some instructions on a sticky note on one of Mr. Benum's computer monitors:
Why do they keep making me use these stupid codes?! Note to self: Start at the first integer on the paper, then skip ahead positions (or behind, if is negative). The integer you land on decodes to an uppercase alphabetic character . Move to the next integer after the one you just decoded and skip ahead (or behind if is negative) spaces from there. Repeat until you (at any point) move to a , at which point the program should terminate immediately. Hey, at least you will always skip to a position that's actually on the page, and there will always be a number after that. Who even designed this stupid code?
Input Specification
The first line of input consists of integer , the number of integers on the paper. The next lines of input contain the integers on the paper in order.
Output Specification
The output is the decoded message in uppercase.
Sample Input 1
9
2
22
5
-2
10
12
0
9
-3
Sample Output 1
EVIL
Explanation of Sample Output 1
You first skip forwards by from the first integer on the page. The decodes to an E
. The next number after is , so you skip backwards from there, landing on the which decodes to a V
. The next integer is a , so you skip forward by to , which decodes to I
. You then skip backward by from , landing on a , which decodes to L
. The next number is , so the program terminates.
Sample Input 2
20
9
1
4
12
4
0
3
1
5
11
-10
16
5
16
-3
14
-9
5
-14
0
Sample Output 2
KIDNAPPED
Comments
RTE ? can someone tell me why my program raises the bad_alloc error
The message terminates when it lands on a zero. There is one case where this happens that you did not consider.