TopCoder problem "NoZero" used in TCCC '04 Qual. 2 (Division I Level Two)



Problem Statement

    *** You may only submit a given problem once - no resubmissions will be accepted. ***



A no-zero number system uses only the digits 1 through 9. So counting begins with 1, the first "counting number", and continues:
  • 1,2,3,4,5,6,7,8,9,11,12,...,19,21,...,98,99,111,112,...
So, in this system 9 is the ninth counting number and 11 is the tenth counting number.

As usual, addition can be defined by reference to the counting sequence. Addition of the i-th counting number and the j-th counting number is defined to mean the (i+j)-th counting number. Thus, in this system 5 + 8 = 14, since 5 is the fifth counting number, 8 is the eighth, and 14 is the thirteenth counting number. Subtraction is the reverse of addition. Create a class NoZero that contains the method subtract that takes two no-zero numbers, big and small, and returns the no-zero value that results from calculating big - small.

 

Definition

    
Class:NoZero
Method:subtract
Parameters:int, int
Returns:int
Method signature:int subtract(int big, int small)
(be sure your method is public)
    
 

Constraints

-big and small do not contain the digit 0
-big is between 1 and 999,999,999 inclusive
-small is between 1 and 999,999,999 inclusive
-big is greater than small
 

Examples

0)
    
111
99
Returns: 1
This big and small are adjacent in the counting sequence. So 99 + 1 = 111 and 111 - 99 = 1.
1)
    
19
11
Returns: 8
2)
    
191
111
Returns: 79
3)
    
11112
9989
Returns: 12

Problem url:

http://www.topcoder.com/stat?c=problem_statement&pm=1107

Problem stats url:

http://www.topcoder.com/tc?module=ProblemDetail&rd=5001&pm=1107

Writer:

dgoodman

Testers:

lbackstrom , schveiguy

Problem categories:

Advanced Math