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 lengthk
consisting of characters R and D
The next line contains the number of values in the encrypted sequence, n n
The last line contains the encrypted sequence itself y yn where yi The values are enclosed in a
set of square brackets ie 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
Input:
DD
Output:
error
Example
Input:
RDD
Output:
Example
Input:
RRRDD
Output:
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
