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 , 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  to 
.
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: , 
 and 
. 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 increaseby one and print
title, and setand
to zero because in each section the numeration of the (sub)subsections starts over again.
 - If the current command is 
subsection title, we increaseby one and print
title, and setto zero because in each subsection the numeration of the subsubsections starts over again.
 - If the current command is 
subsubsection title, we increase onlyand print
title. 
Comments