Decoding an LZW stream · Compiler
Decoding an LZW stream
Decode an LZW stream with initial dictionary entries 0 = A and 1 = B. Emit the first code's entry. For each later code, use its dictionary entry if present. If it equals the next unused code, its text is the previous piece followed by the first letter of that previous piece. Emit the current piece and add the previous piece followed by the first letter of the current piece at the next unused code, starting at 2.
- Input
- The first line contains the number of codes n (1 <= n <= 50). The second line contains n space-separated nonnegative integer codes. The first is 0 or 1. Each later code is at most the next unused code when it is read. The dictionary is never reset.
- Output
- Print the decoded pieces concatenated into one uppercase word.
Compiler Explorer runs your code when you run or check it.
Loading your exercise draft…