Question: The Department of Defense is developing a new encryption method that is used for transporting the country s secret military codes. The codes themselves have

The Department of Defense is developing a new encryption method that is used for transporting the countrys
secret military codes. The codes themselves have been encrypted by new award winning encryption methodology. A
separate decoding key is used to decrypt the sequence and return it back to the original. Your task is to write a
program in c that given an encrypted sequence along with the decoding key, recovers the original sequence.
The decoding key contains two different characters encoding two different operations: R and D.
the character R reverses the numerical sequence;
the character D drops the first element of the sequence.
There are a few cases where the original data is irrecoverable due to transmission errors. Your program should be
able to detect that and print error, instead of the recovered sequence. The errors should be reported whenever
there is an instruction that attempts to drop the first element of an empty sequence. (Note, that reversing an empty
sequence should not produce any problems.)
Input
The first line contains the decoding key k(1<= length(k)<=105
) consisting of characters R and D.
The next line contains the number of values in the encrypted sequence, n (0<= n <=105
).
The last line contains the encrypted sequence itself [y1,..., yn], where (1<= yi <=100). The values are enclosed in a
set of square brackets (i.e., start with [ and end with ]). The individual values are separated by commas and
nothing else.
Output
A single line containing either the decrypted sequence or error. The resulting list should start with [ and end
with ]. The integers in the input and output list are separated by commas and nothing else.
Example 1
Input:
DD
1
[42]
Output:
error
Example 2
Input:
RDD
4
[1,2,3,4]
Output:
[2,1]
Example 3
Input:
RRRDD
4
[1,2,3,4]
Output:
[2,1]

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!