Connection Status:
Competition Arena > DigitHoles
SRM 483 · 2010-03-12 · by espr1t · Simple Search, Iteration
Class Name: DigitHoles
Return Type: int
Method Name: numHoles
Arg Types: (int)
Problem Statement

Problem Statement

Elly's evil teacher assistant Torb has given her the following puzzle: 42 -> 1, 1337 -> 0, 669 -> 3, 1882 -> 4, 688 -> 5, 12345 -> 1, 67890 -> 5, 123 -> 0, 456 -> 2, 789 -> 3. Given this information, 45678 -> ? Thanks to her fast thinking and problem-solving intuition she has found the solution: Google. The answer turned out to be the total number of "holes" in the digits of the number's decimal representation (with no extra leading zeroes). We can see that the digits 1, 2, 3, 5, and 7 contain no holes, 0, 4, 6, and 9 each has one hole, and 8 contains two holes. Therefore the answer to the puzzle is 45678 -> 1 + 0 + 1 + 0 + 2 = 4.

You want to impress Elly, so you decide to write a program that will find the correct answer for certain integers. Given an int number, return the total number of holes in that number.

Notes

  • In some fonts, the digit '4' might not contain an enclosed hole, but for this problem you should assume it does.

Constraints

  • number will be between 1 and 1000, inclusive.
Examples
0)
42
Returns: 1

4 has one hole, and 2 has no holes.

1)
669
Returns: 3

Both sixes are counted.

2)
688
Returns: 5

Note that 8 is the only digit that has 2 holes.

3)
123
Returns: 0

A number without holes.

4)
456
Returns: 2
120)
1000
Returns: 3

One thousand.

Submissions are judged against all 131 archived test cases, of which 6 are shown here. Case numbers match the judge’s.

Coding Area

Language: C++17 · define a public class DigitHoles with a public method int numHoles(int number) · 131 test cases · 2 s / 256 MB per case

Submitting as anonymous