#P8871. [传智杯 #5 初赛] C-莲子的排版设计学

[传智杯 #5 初赛] C-莲子的排版设计学

Background

You cannot rest now; deadlines are wandering around you.

Lianzi is rushing to finish her programming assignment. Besides writing the program code, it is also important to typeset the submitted assignment nicely to leave a good impression on the teaching assistant.

As everyone knows, code and some special kinds of text in an article need line numbers, but they are often very long, and adding them by hand is easy to make mistakes. So Lianzi decided to build her own tool and write a line number generator.

Problem Description

Lianzi wants to implement the following function: given a text file as input, add line numbers to it.

Here are the definitions of three basic concepts in this problem:

  • Text characters consist of all visible characters in ASCII\textsf{ASCII}, plus the space character (ASCII=32\textsf{ASCII}=32).
  • One line of characters consists of several (possibly 00) text characters, and exactly one newline character (ASCII=10\textsf{ASCII}=10) at the end.
  • A text file consists of several (at least 11) lines of characters. The number of lines in the text file is the number of lines that make it up.

Here is how to add line numbers in this problem:

  • Suppose the text file has mm lines in total. Let the digit width of the positive integer mm be ss. Then, at the beginning of each line, there will be a length of s+1s+1 reserved for displaying the line number.
  • For the ii-th line, suppose the digit width of ii is tt. Then the line number displayed for this line will be $\underbrace{\texttt{␣␣...␣}}_{s-t\text{ spaces}}\ i\ \texttt{␣}$, where \texttt{␣} denotes a space.

Here is an example:

$$\boxed{\begin{aligned} &\verb!#include<iostream>!\\ &\verb!using namespace std;!\\ &\verb!int main(){!\\ &\verb! int a, b;!\\ &\verb! cin >> a >> b;!\\ &\verb! cout << a + b << endl;!\\ &\verb! cout << a - b << endl;!\\ &\verb! cout << a * b << endl;!\\ &\verb! cout << a / b << endl;!\\ &\verb! return 0;!\\ &\verb!}! \end{aligned}} \Rightarrow \boxed{\begin{aligned} &\verb! 1 #include<iostream>!\\ &\verb! 2 using namespace std;!\\ &\verb! 3 int main(){!\\ &\verb! 4 int a, b;!\\ &\verb! 5 cin >> a >> b;!\\ &\verb! 6 cout << a + b << endl;!\\ &\verb! 7 cout << a - b << endl;!\\ &\verb! 8 cout << a * b << endl;!\\ &\verb! 9 cout << a / b << endl;!\\ &\verb!10 return 0;!\\ &\verb!11 }! \end{aligned}}$$

To make it easier to observe, all spaces are replaced here with the \verb!␣! character that represents a space.

$$\boxed{\begin{aligned} &\verb!#include<iostream>!\\ &\verb!using␣namespace␣std;!\\ &\verb!int␣main(){!\\ &\verb!␣␣␣␣int␣a,␣b;!\\ &\verb!␣␣␣␣cin␣>>␣a␣>>␣b;!\\ &\verb!␣␣␣␣cout␣<<␣a␣+␣b␣<<␣endl;!\\ &\verb!␣␣␣␣cout␣<<␣a␣-␣b␣<<␣endl;!\\ &\verb!␣␣␣␣cout␣<<␣a␣*␣b␣<<␣endl;!\\ &\verb!␣␣␣␣cout␣<<␣a␣/␣b␣<<␣endl;!\\ &\verb!␣␣␣␣return␣0;!\\ &\verb!}! \end{aligned}} \Rightarrow \boxed{\begin{aligned} &\verb!␣1␣#include<iostream>!\\ &\verb!␣2␣using␣namespace␣std;!\\ &\verb!␣3␣int␣main(){!\\ &\verb!␣4␣␣␣␣␣int␣a,␣b;!\\ &\verb!␣5␣␣␣␣␣cin␣>>␣a␣>>␣b;!\\ &\verb!␣6␣␣␣␣␣cout␣<<␣a␣+␣b␣<<␣endl;!\\ &\verb!␣7␣␣␣␣␣cout␣<<␣a␣-␣b␣<<␣endl;!\\ &\verb!␣8␣␣␣␣␣cout␣<<␣a␣*␣b␣<<␣endl;!\\ &\verb!␣9␣␣␣␣␣cout␣<<␣a␣/␣b␣<<␣endl;!\\ &\verb!10␣␣␣␣␣return␣0;!\\ &\verb!11␣}! \end{aligned}}$$

Input Format

The input contains several lines, which form the original text file.

Output Format

The output contains several lines, which form the text file after adding line numbers.

#include<iostream>
using namespace std;
int main(){
    int a, b;
    cin >> a >> b;
    cout << a + b << endl;
    cout << a - b << endl;
    cout << a * b << endl;
    cout << a / b << endl;
    return 0;
}

 1 #include<iostream>
 2 using namespace std;
 3 int main(){
 4     int a, b;
 5     cin >> a >> b;
 6     cout << a + b << endl;
 7     cout << a - b << endl;
 8     cout << a * b << endl;
 9     cout << a / b << endl;
10     return 0;
11 }

public class Main {
    public static void main(String[] args) throws Exception {
        int b = 0, c = 0;
        for (int a = 123; a < 333; a++) {
            int[] array = new int[10];
            Boolean flag = true;
            b = a * 2;
            c = a * 3;
            array[a / 100] = 1;
            array[a / 10 % 10] = 1;
            array[a % 10] = 1;

            array[b / 100] = 1;
            array[b / 10 % 10] = 1;
            array[b % 10] = 1;

            array[c / 100] = 1;
            array[c / 10 % 10] = 1;
            array[c % 10] = 1;
            for (int i = 1; i < array.length; i++) {
                if (array[i] != 1) {
                    flag = false;
                    break;
                }
            }
            if (flag)
                System.out.println(a + " " + b + " " + c);
        }
    }
}
 1 public class Main {
 2     public static void main(String[] args) throws Exception {
 3         int b = 0, c = 0;
 4         for (int a = 123; a < 333; a++) {
 5             int[] array = new int[10];
 6             Boolean flag = true;
 7             b = a * 2;
 8             c = a * 3;
 9             array[a / 100] = 1;
10             array[a / 10 % 10] = 1;
11             array[a % 10] = 1;
12 
13             array[b / 100] = 1;
14             array[b / 10 % 10] = 1;
15             array[b % 10] = 1;
16 
17             array[c / 100] = 1;
18             array[c / 10 % 10] = 1;
19             array[c % 10] = 1;
20             for (int i = 1; i < array.length; i++) {
21                 if (array[i] != 1) {
22                     flag = false;
23                     break;
24                 }
25             }
26             if (flag)
27                 System.out.println(a + " " + b + " " + c);
28         }
29     }
30 }

Tao hua kai yo li hua kai, jie jie mei mei dong qi lai;
Tao hua kai yo li hua kai, jie jie mei mei tiao qi lai.
    Gei ni zi ji, chun yi mai huai (yi ya yo);
    Gei xin shang ren, chun se man kai.
Tao hua kai yo li hua kai, jie jie mei mei dong qi lai; 
Tao hua kai yo li hua kai, jie jie mei mei tiao qi lai.
    Gei tong bao men, chun yi man huai, hai hai yo;
    Gei zhe da di, chun se quan kai!!!
Cong na nu jiang nan, dao mo he bei,
    Dao chu dou you hua rong ming mei.
Lai hui hui shou, zai diao ge tou,
    Wu xian chun guang zai wo xiong.
Cong jing cheng, dao yuan ye,
    Dao chu dou you sheng de xi yue.
Lai hui hui shou, zai yan ran huang ge tou,
    Wu xian CHUN GUANG XIAN ZU GUO!!!
Tao hua kai yo li hua kai, Jiong xian mei mei dong qi lai;
Tao hua kai yo li hua kai, Jie jie mei mei tiao qi lai.
    Gei ni zi ji, chun yi mai huai chun yi man huai yi ya yo;
    Gei xin shang ren, chun se man kai chun se man kai.
Tao hua kai yo li hua kai, Jie jie mei mei dong qi lai;
Tao hua kai yo li hua kai, Jie jie mei mei tiao qi lai.
    Gei tong bao men, chun yi man huai, hai hai yo;
    Gei zhe da di, chun se quan kai!!!
Cong na nu jiang nan, dao mo he bei,
    Dao chu dou you hua rong ming mei.
Lai hui hui shou, zai diao ge tou,
    Wu xian chun guang zai wo xiong.
Cong jing cheng, dao yuan ye,
    Dao chu dou you sheng de xi yue.
Lai hui hui shou, zai yan ran huang ge tou,
    Wu xian CHUN GUANG XIAN ZU GUO!!!
Lai hui hui shou, zai yan ran huang ge tou,
    Wu xian CHUN GUANG XIAN ZU GUO!!!

 1 Tao hua kai yo li hua kai, jie jie mei mei dong qi lai;
 2 Tao hua kai yo li hua kai, jie jie mei mei tiao qi lai.
 3     Gei ni zi ji, chun yi mai huai (yi ya yo);
 4     Gei xin shang ren, chun se man kai.
 5 Tao hua kai yo li hua kai, jie jie mei mei dong qi lai; 
 6 Tao hua kai yo li hua kai, jie jie mei mei tiao qi lai.
 7     Gei tong bao men, chun yi man huai, hai hai yo;
 8     Gei zhe da di, chun se quan kai!!!
 9 Cong na nu jiang nan, dao mo he bei,
10     Dao chu dou you hua rong ming mei.
11 Lai hui hui shou, zai diao ge tou,
12     Wu xian chun guang zai wo xiong.
13 Cong jing cheng, dao yuan ye,
14     Dao chu dou you sheng de xi yue.
15 Lai hui hui shou, zai yan ran huang ge tou,
16     Wu xian CHUN GUANG XIAN ZU GUO!!!
17 Tao hua kai yo li hua kai, Jiong xian mei mei dong qi lai;
18 Tao hua kai yo li hua kai, Jie jie mei mei tiao qi lai.
19     Gei ni zi ji, chun yi mai huai chun yi man huai yi ya yo;
20     Gei xin shang ren, chun se man kai chun se man kai.
21 Tao hua kai yo li hua kai, Jie jie mei mei dong qi lai;
22 Tao hua kai yo li hua kai, Jie jie mei mei tiao qi lai.
23     Gei tong bao men, chun yi man huai, hai hai yo;
24     Gei zhe da di, chun se quan kai!!!
25 Cong na nu jiang nan, dao mo he bei,
26     Dao chu dou you hua rong ming mei.
27 Lai hui hui shou, zai diao ge tou,
28     Wu xian chun guang zai wo xiong.
29 Cong jing cheng, dao yuan ye,
30     Dao chu dou you sheng de xi yue.
31 Lai hui hui shou, zai yan ran huang ge tou,
32     Wu xian CHUN GUANG XIAN ZU GUO!!!
33 Lai hui hui shou, zai yan ran huang ge tou,
34     Wu xian CHUN GUANG XIAN ZU GUO!!!

Hint

Constraints and Notes

For all testdata, the total number of characters in the input text file (including newline characters) does not exceed 2×1042\times 10^4. Also, the input is guaranteed to be valid.

During judging, trailing spaces at the end of each line and the final newline at the end of the file will be ignored. Therefore, you may decide whether to output extra trailing spaces at the end of lines. For contestants using Java or Python, please pay attention to input/output efficiency.

Translated by ChatGPT 5