NoEights
SRM 355 · 2007-06-20 · by Petr
Problem Statement
Cyclists don't like the number eight because it symbolizes a broken wheel. Recently, the mayor of Moscow decided to force all cyclists to get an identification number. Vasya was presented with the following choice: he can choose any number between low and high, inclusive. He wants his number to contain as few eights as possible. Return the minimal possible number of eights he can have in his number.
Constraints
- low will be between 1 and 2000000000, inclusive.
- high will be between low and 2000000000, inclusive.
1 10 Returns: 0
Any number except 8 will do.
88 88 Returns: 2
The only possible number is 88.
800 899 Returns: 1
The first 8 is unavoidable.
8808 8880 Returns: 2
8 88 Returns: 0
Submissions are judged against all 148 archived test cases, of which 5 are shown here. Case numbers match the judge’s.
Language: C++17 · define a public class NoEights with a public method int smallestAmount(int low, int high) · 148 test cases · 2 s / 256 MB per case