Editorial for COCI '21 Contest 5 #1 Kemija


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.

The task requires us to check if there is an equal number of atoms on each side of the equation. For each side of the equation, we'll maintain a list (array) to keep track of the number of occurrences of each letter on that side. In the end, we'll compare the two lists and if they are equal print DA, and otherwise NE. After each equation, we must make sure to clear each of these lists.

To count how many atoms are on each side, first we separate the equation into two strings, each representing one side of the equation. In Python, this can be done using the split() function, and for other programming languages, this can be done by iterating through the string and searching for a sequence of characters equaling ->. After we have split the left and the right side, in a similar way we can split each of the sides into a list of strings representing the molecules. Then we count how many atoms are in each molecule and add this to the total for the corresponding side. To count the number of atoms in a molecule, we iterate over the string representing the molecule and for each letter we look at the number coming after it (if it doesn't exist we assume it's 1) and multiply the count with this number. We also multiply with the number at the beginning of the string if there is one.


Comments

There are no comments at the moment.