Connection Status:
Competition Arena > MirrorNumber
SRM 363 · 2007-08-11 · by mateuszek · Recursion, Search, Simple Math
Class Name: MirrorNumber
Return Type: int
Method Name: count
Arg Types: (string, string)
Problem Statement

Problem Statement

A number is written on a traditional digital display. If the display looks identical when flipped horizontally (i.e., around a vertical axis), the number is called a "mirror number". On a digital display, the digits 0, 1 and 8 are symmetrical, and the digits 2 and 5 are mirror images of each other. No other digits make sense when flipped horizontally. For example, 0, 101 and 1521 are all mirror numbers, while 1221 and 1010 are not (see images below). Given two Strings A and B, both representing integers with no extra leading zeroes, return the number of mirror numbers between A and B, inclusive.

Mirror numbers (both remain unchanged after mirroring):
    

Not mirror numbers (1221 mirrors to 1551, and 1010 mirrors to 0101):
    

Constraints

  • A will represent an integer between 0 and 10^18, inclusive.
  • B will represent an integer between A and 10^18, inclusive.
  • Both A and B will have no extra leading zeros.
Examples
0)
"0"
"10"
Returns: 3

There is only 0, 1 and 8 here.

1)
"0"
"100"
Returns: 7

Few more: 11, 25, 52, 88.

2)
"143"
"23543"
Returns: 54
3)
"1234"
"23452354235234"
Returns: 87478
4)
"0"
"1000000000000000000"
Returns: 3124999

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

Coding Area

Language: C++17 · define a public class MirrorNumber with a public method int count(string A, string B) · 78 test cases · 2 s / 256 MB per case

Submitting as anonymous