TopcoderArchiveVisit Topcoder
Archive
Algorithm problem

NoZero

Problem statement, definition, constraints, and public examples.

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

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