UCC Coding Competition '21 P1 - Counterfeit Detection

View as PDF

Submit solution

Points: 3 (partial)
Time limit: 2.0s
Memory limit: 256M

Author:
Problem type

In your strange local currency, there should only be $4, $6 and $25 coins. Unfortunately, a counterfeiter just added a whole bunch of fake $2 coins into circulation!

Your job is to determine how many counterfeited coins are mixed into a row of coins. This is more difficult than it looks. The coins are rectangular, so a row of coins looks something like this:

\displaystyle \begin{array}{|c|c|c|c|c|c|c|}\hline
6 & 2 & 25 & 4 & 4 & 25 & 2 \\\hline
\end{array}

In order to count all the coins, you use a scanning machine that reads the digits on the top of the coins one by one. For the row of coins shown above, your machine will produce the string 622544252.

Given a sequence of digits generated by the machine, please determine how many of the coins are counterfeit $2 coins. As there are no $5 coins in circulation, you can assume that if you see 25 in the sequence, it represents a non-counterfeit $25 coin. Otherwise, if you see a 2 in the sequence that is not followed by a 5, you can assume that it is a counterfeit coin.

Input Specification

The first and only line of input will contain a sequence of digits from your coin-scanning machine, such as 622544252.

Output Specification

Please output the number of counterfeit ($2) coins in the row of coins.

Constraints and Partial Marks

For all test cases, the string is 999 characters or fewer in length.

Additionally, for 4 out of 10 available marks, there are no $25 coins, so the string doesn't contain the digit 5.

Sample Input

2256624425252

Sample Output

3

Explanation for Sample Output

The sample input represents this row of coins:

\displaystyle \begin{array}{|c|c|c|c|c|c|c|c|c|c|}\hline
2 & 25 & 6 & 6 & 2 & 4 & 4 & 25 & 25 & 2 \\\hline
\end{array}

In this row, there are three counterfeit $2 coins.


Comments


  • 0
    Hanzo  commented on June 16, 2023, 5:02 p.m.

    I don't understand why I get 0/4 on batch #1 but 6/6 for batch #2


    • 0
      Hanzo  commented on June 16, 2023, 5:18 p.m.

      I know 4 of the points has a test case where there are no $25 coins, but I tried all the possible test cases I can think of and they all pass. Can anyone recommend any test cases?


      • 0
        Kirito  commented on June 16, 2023, 6:29 p.m. edited

        If you remove your debug prints on your latest solution, you pass. In the future, you can join the DMOJ Discord if you have any problems you need help with.