Editorial for COCI '21 Contest 2 #1 Kaučuk
Submitting an official solution before solving the problem yourself is a bannable offence.
For the subtask in which 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
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:
- If the current command is
section title
, we increase by one and printtitle
, and set and to zero because in each section the numeration of the (sub)subsections starts over again. - If the current command is
subsection title
, we increase by one and printtitle
, and set to zero because in each subsection the numeration of the subsubsections starts over again. - If the current command is
subsubsection title
, we increase only and printtitle
.
Comments