TopCoder problem "SoldierLabeling" used in SRM 446 (Division II Level One)



Problem Statement

    

Tom is a little boy who likes to collect toys. On his birthday, his mom bought him a box of toy soldiers as a gift. There are n soldiers in the box, labeled 1 to n on their uniforms. The numbers are written with no leading zeroes. Tom starts counting the soldiers, but he soon finds that it's difficult to count them all. He decides to count only the soldiers with labels that have length between lowerBound and upperBound, inclusive. Return the number of soldiers that Tom will count.

 

Definition

    
Class:SoldierLabeling
Method:count
Parameters:int, int, int
Returns:int
Method signature:int count(int n, int lowerBound, int upperBound)
(be sure your method is public)
    
 

Constraints

-n will be between 1 and 10,000,000, inclusive.
-lowerBound will be between 1 and 8, inclusive.
-upperBound will be between lowerBound and 8, inclusive.
 

Examples

0)
    
100
2
2
Returns: 90
Here there are 100 soldiers and they're labeled 1 to 100. The labels between 10 and 99, inclusive, are of length 2.
1)
    
31
2
3
Returns: 22
Here there are 31 soldiers and we're looking for labels of length between 2 and 3, inclusive. There are no labels of length 3. Labels between 10 and 31, inclusive, are of length 2.
2)
    
1
2
8
Returns: 0
Here there is only one soldier and it is labeled 1. We're looking for labels of length between 2 and 8, inclusive, and there are none.
3)
    
10000000
8
8
Returns: 1
Label 10000000 is the only one here of length 8.
4)
    
2718317
3
7
Returns: 2718218

Problem url:

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

Problem stats url:

http://www.topcoder.com/tc?module=ProblemDetail&rd=13900&pm=10574

Writer:

crazyb0y

Testers:

PabloGilberto , ivan_metelsky , Chmel_Tolstiy , MThorn

Problem categories:

Math