Editorial for COCI '12 Contest 6 #1 Baka
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.
Submitting an official solution before solving the problem yourself is a bannable offence.
We have to do a for-loop through the string and for each character (letter) determine on which digit of the phone it is found.
Let us make an auxiliary string where we keep the starting letters on the digits (A
, D
, G
, J
, M
, P
, T
, W
). For a given letter we will iterate through the auxiliary string and locate the last letter in it that is less than or equal to the given letter (for example, if a given letter is O
, the corresponding letter in the auxiliary string is M
). We can now replace the given letter with the found letter since it is a letter that belongs to the same digit. Now we easily determine this digit using the position of the found letter in the auxiliary string and increase the final solution by .
Comments