TopCoder problem "OneDigitDifference" used in Member SRM 491 (Division II Level One)



Problem Statement

    We say that two integer numbers differ from each other by one digit, when in their decimal notation, possibly with leading zeros, they will differ in exactly one position. For example numbers 128 and 28 differ by one digit:
	128
	028
But numbers 2047 and 40 differ by two digits:
	2047
	0040
Given the number N, find and return the smallest possible non-negative number M, such that number N and M differ from each other by exactly one digit.
 

Definition

    
Class:OneDigitDifference
Method:getSmallest
Parameters:int
Returns:int
Method signature:int getSmallest(int N)
(be sure your method is public)
    
 

Constraints

-N will be between 0 and 2,000,000,000, inclusive.
 

Examples

0)
    
9
Returns: 0
0 is the smallest non-negative number and differs by only one digit.
1)
    
0
Returns: 1
The result number is not always smaller than N.
2)
    
900000123
Returns: 123
Leading zeros in the result are okay:
 900000123
 000000123
3)
    
30000
Returns: 0
Leading zeros are okay also with 0 as a result:
 30000
 00000
4)
    
47
Returns: 7
5)
    
1907654321
Returns: 907654321

Problem url:

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

Problem stats url:

http://www.topcoder.com/tc?module=ProblemDetail&rd=14244&pm=11007

Writer:

Mimino

Testers:

Rustyoldman , ivan_metelsky , rng_58 , wrong

Problem categories:

Simple Math