Skills101
← All coding problems

Run-Length Decoding

easyPlacement Coding+10 XPTime limit 2s

Undo run-length encoding. The encoded string is a list of blocks; each block is a lowercase letter followed by a count (one or more digits). Print each letter repeated count times. a3b1c12 becomes aaab followed by twelve cs.

Input: one line with the encoded string.

Output: the decoded string.

Constraints: 1 ≤ encoded length ≤ 10⁵; every count is between 1 and 10⁵; the decoded string has at most 2·10⁵ characters.

Think about it: a count can have several digits (c12), so build the number digit by digit: count = count * 10 + digit.

Sample input 1

a3b1c12

Sample output 1

aaabcccccccccccc

Sample input 2

x1

Sample output 2

x

Read input from standard input and print the answer to standard output. Your code runs in a secure sandbox against the samples (Run) and hidden tests (Submit).

Loading editor…

Log in to run and submit your code — it's free.