Look-and-Say String
InterviewTime limit1sMemory limit128 MB
Apply the look-and-say run-length encoding to a digit string n times and print the resulting string.
- Level
Easy3 of 10
- Topics
- String, Implementation, Simulation, Two pointers
- Solved
- No attempts yet
Problem
You are given a string composed only of the digits 0 through 9. Consider the following operation that turns it into a new string.
Read the string from the left, one character at a time. Whenever the same digit appears times in a row, write the count immediately followed by the digit , with no space between them. Reading all the way to the right end and finishing the last write together count as a single operation, no matter how many individual writes happened along the way. Each operation from the second onward is applied the same way, using the string produced by the previous operation as its new input.
For example, given "122244", reading from the left there is one 1, three 2s, and two 4s, so one operation yields "113224". For "44444444444" (eleven 4s), one operation yields "114".
Write a program that, for a given string of length at most 100, outputs the string obtained after performing the operation times, where .
Input
Two lines. The first line contains the number of operations . The second line contains the initial string.
Output
Output, on a single line, the string obtained after performing the operation the specified number of times, followed by a newline.