House Number Sign
InterviewTime limit1sMemory limit128 MB
Compute the total width of a house-number sign given fixed per-digit widths and 1 cm margins between digits and at both ends, for each input number until 0 appears.
- Level
Easy2 of 10
- Topics
- Implementation, String, Math
- Solved
- No attempts yet
Problem
Jaeseok makes number signs that are attached to front doors. Each sign contains an address number, and it needs fixed margins between digits and at both ends. Different digits also take different widths.
The rules are as follows.
- There is a 1 cm margin between every pair of adjacent digits.
- The digit 1 takes 2 cm, and the digit 0 takes 4 cm. Every other digit takes 3 cm.
- There is a 1 cm margin between the sign boundary and the nearest digit on both the left and the right.

For the number 120 shown above, there are two gaps between digits. The digit widths are 2 cm for 1, 3 cm for 2, and 4 cm for 0. Adding the 2 cm of outer margins gives a total width of 2 + 2 + 3 + 4 + 1 + 1 = 13 cm.
For each given address number, determine the total width needed for its number sign.
Input
Each line contains one number N to be written on a sign. N satisfies 1 <= N <= 9999.
Input continues until a line containing 0 appears. The final 0 is a terminator and must not be processed.
Output
For each number, output the total width required for its number sign as an integer.
Print the answers in input order, one per line.