TopcoderArchiveVisit Topcoder
SRM29 Apr 2002
SRM 84

LitLCD

Problem statement, definition, constraints, and public examples.

Problem Statement

Given an int, how many LCD lines would show up on an old 8-digit calculator to represent the int?

Below are 10 digits and 'e' and '-' commonly used to display numbers on a calculator.

 _      _  _       _   _  _   _   _     _
| |  |  _| _| |_| |_  |_   | |_| |_|   |_   _
|_|  | |_  _|   |  _| |_|  | |_|  _|   |_

'0' has 6 lines, '1' has 2 lines, '2' has 5 lines
'3' has 5 lines, '4' has 4 lines, '5' has 5 lines
'6' has 6 lines, '7' has 3 lines, '8' has 7 lines
'9' has 6 lines, 'e' has 5 lines, and '-' has 1 line

The calculator only has 8 digits, and '-' takes up one of them: it can display "-1234567" or "12345678" but not "-12345678". If the number is too big to fit on the display, the calculator will display the error "0E" (consisting of 11 lines).

The calculator will never show leading 0s. For example, 1 will always show as '1', not as '000001', and 0 will show as '0' not as '00'. The calculator will never show '-0'. 0 will always show as '0' (6 lines).

Definition

Class:
LitLCD
Method:
numLines
Parameters:
int
Returns:
int
Method signature:
int numLines(int numToDisplay)
(be sure your method is public)

Notes

  • if the number is out of range for the calculator, you should return 11 (the number of LCD lines in 0E).

Constraints

  • numToDisplay will be between -999,999,999 to 999,999,999, inclusive

Examples

  1. 1024
    Returns: 17
    _ _ | | | _| |_| | |_| |_ | 2 for '1', 6 for '0', 5 for '2', 4 for '4'
  2. -1024
    Returns: 18
  3. 12345678
    Returns: 37
  4. -999999999
    Returns: 11
  5. 0
    Returns: 6
  6. 111
    Returns: 6
  7. 99999999
    Returns: 48
  8. 100000000
    Returns: 11
Back to all problems