#P8871. Line Numbering in Text Files
Line Numbering in Text Files
Line Numbering in Text Files
This problem requires you to add line numbers to a given text file. The text file consists of one or more lines, where each line is comprised of any number (possibly zero) of printable ASCII characters (including space, with ASCII code 32) followed by exactly one newline character (ASCII code 10). The total number of lines in the file is denoted as \(m\).
The procedure for adding line numbers is as follows: Let \(s\) be the digit width of \(m\) (i.e. the number of digits in \(m\)). For the \(i\)-th line, let \(t\) be the digit width of \(i\). The line number is then printed at the beginning of the line as:
[ \underbrace{\texttt{\ ␣\ ␣\ ...\ ␣}}_{s-t\text{ spaces}} ; i ; \texttt{\ } ]
This means you should pad the line number on the left with \(s-t\) spaces, then print the number \(i\) and then an additional space, before printing the rest of the original line.
For example, if the input source code has 11 lines the digit width \(s\) is 2. Thus, the first line will have its line number printed as "␣1 " (1 space, then "1", then a space) and the eleventh line as "11 ". In the statements below, visible spaces are represented by the special symbol ␣ for clarity.
inputFormat
The input contains a text file with one or more lines. Each line is composed of printable ASCII characters and ends with a newline character.
outputFormat
Output the text file with each line prefixed by its corresponding line number. The line number for the \(i\)-th line should be printed using a fixed width of \(s+1\) characters where \(s\) is the number of digits in the total number of lines \(m\). More precisely, the prefix for line \(i\) is constructed as follows:
[ \underbrace{\texttt{\ ␣\ ␣\ ...\ ␣}}_{s-t\text{ spaces}} ; i ; \texttt{\ } ]
After the prefix, the original line content is printed exactly as it appears in the input.
sample
Hello, World!
1 Hello, World!
</p>