Connection Status:
Competition Arena > LitLCD
SRM 84 · 2002-04-29 · by Echo
Class Name: LitLCD
Return Type: int
Method Name: numLines
Arg Types: (int)
Problem Statement

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).

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
0)
17
Returns: 5
1)
11118888
Returns: 36
2)
99999999
Returns: 48
3)
88888888
Returns: 56
4)
100000000
Returns: 11
44)
1024
Returns: 17

_ _ | | | _| |_| | |_| |_ | 2 for '1', 6 for '0', 5 for '2', 4 for '4'

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

Coding Area

Language: C++17 · define a public class LitLCD with a public method int numLines(int numToDisplay) · 52 test cases · 2 s / 256 MB per case

Submitting as anonymous