Write a program that takes in a string where every line consists of the character 0
indented by some number of spaces. The top line is not indented and every other line will be indented by at most one more space than the line just before it.
No lines will have trailing spaces but you may optionally assume there is a single trailing newline.
For example, the input might look something like this:
0
0
0
0
0
0
0
0
0
0
0
0
0
0
Your task is to number it like a hierarchical outline, using increasing positive integers as the line headers. This would be the output for the example:
1
1
1
2
2
2
1
2
3
1
3
1
1
2
Note how every hierarchical indentation level has its own set of increasing numbers, even if they only go up to one.
In the output, there should be no trailing spaces, but there may optionally be a single trailing newline.
Write a full program that takes the input string via stdin or command line, or write a function that takes the string in as an argument. Print the result or return it as a string.
The shortest code in bytes wins.
Examples
If the empty string is input, the empty string should be output.
The next most trivial example is the input
0
which should become
1
Large example - Input:
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
Output:
1
1
1
2
1
3
1
2
1
2
1
1
2
3
4
2
3
1
2
3
2
1
1
2
1
2
3
4
5
6
7
8
9
10
11
1
1
1
12
1
3
4
5
1
1
1
1
1
1
2
2
2
2
2
2
1
2
1
2
6
7