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

There are no comments at the moment.