Connection Status:
Competition Arena > HouseNumbering
SRM 801 · 2021-02-22 · by misof · Brute Force, Simple Search, Iteration
Class Name: HouseNumbering
Return Type: int[]
Method Name: prepareDigits
Arg Types: (int, int)
Problem Statement

Problem Statement

You have gotten a new job: your task is to put house numbers onto a range of houses. All these houses are on one side of a long road. The first of these houses (the one with the smallest number) has the number firstHouse. There are numberOfHouses houses in the range of houses you should number.

As is customary, the street uses odd house numbers for one side of the street and even house numbers for the other side. As the houses you should number are on the same side, their numbers all have the same parity.

Before you go to the street, you need to purchase the material you need. The hardware store only sells individual digits. Calculate how many copies of each digit you'll need. Return a int[] with exactly 10 elements, element x being the number of times the digit x occurs in your collection of house numbers.

Constraints

  • firstHouse will be between 1 and 1000, inclusive.
  • numberOfHouses will be between 1 and 1000, inclusive.
Examples
0)
7
4
Returns: {0, 3, 0, 1, 0, 0, 0, 1, 0, 1 }

The four houses have numbers 7, 9, 11 and 13. You need three digits 1 and one each of digits 3, 7, and 9.

1)
2
6
Returns: {1, 2, 2, 0, 1, 0, 1, 0, 1, 0 }

These houses have numbers 2, 4, 6, 8, 10, and 12. Make sure you don't forget the digit 0 you need for the number 10.

2)
997
1
Returns: {0, 0, 0, 0, 0, 0, 0, 1, 0, 2 }
3)
160
47
Returns: {15, 25, 42, 5, 14, 2, 14, 5, 14, 5 }
4)
1000
1000
Returns: {400, 700, 900, 200, 400, 200, 400, 200, 400, 200 }

Submissions are judged against all 56 archived test cases, of which 5 are shown here. Case numbers match the judge’s.

Coding Area

Language: C++17 · define a public class HouseNumbering with a public method vector<int> prepareDigits(int firstHouse, int numberOfHouses) · 56 test cases · 2 s / 256 MB per case

Submitting as anonymous