Editorial for COCI '21 Contest 2 #1 Kaučuk


Remember to use this editorial only when stuck, and not to copy-paste code from it. Please be respectful to the problem author and editorialist.
Submitting an official solution before solving the problem yourself is a bannable offence.

For the subtask in which n \le 3, it is sufficient to examine a few possible cases. Because only the sections can stand by themselves, the first command has to be section. The second command can be either section or subsection. Depending on the second command, the third is either section or subsection, or in the other case section, subsection or subsubsection. These five options can be checked using if statements.

In the subtask in which only the section command appears, it is sufficient to number the titles of sections with positive integers from 1 to n.

The subtask in which only the section and subsection commands appear are solved analogously to the entire solution, but without taking into account the subsubsection commands.

For all the points, the task can be solved by keeping track of a counter for each level: S_0, S_1 and S_2. In the beginning, all of the counters are set to zero. We iterate with a for loop over the input:

  • If the current command is section title, we increase S_0 by one and print S_0 title, and set S_1 and S_2 to zero because in each section the numeration of the (sub)subsections starts over again.
  • If the current command is subsection title, we increase S_1 by one and print S_0.S_1 title, and set S_2 to zero because in each subsection the numeration of the subsubsections starts over again.
  • If the current command is subsubsection title, we increase only S_2 and print S_0.S_1.S_2 title.

Comments

There are no comments at the moment.