Connection Status:
Competition Arena > NextLuckyNumber
2018 TCO Semi 2 · 2018-11-14 · by misof · Brute Force, Simple Math, Simple Search, Iteration
Class Name: NextLuckyNumber
Return Type: long
Method Name: getTicket
Arg Types: (long long, int, int)
Problem Statement

Problem Statement

Jitka's birthday is coming up and Emanuel is thinking about a present for her. As he is a poor student, he decided to buy her a scratch-off lottery ticket.

Emanuel remembers that Jitka's lucky digit is digit. He also remembers that this is her age-th birthday. Hence, he would like to bring her a ticket whose serial number contains exactly age copies of the digit digit.

The serial number of the last ticket that was already sold is lastTicket. What is the next ticket Emanuel should buy?

Constraints

  • lastTicket will be between 1 and (10^17 - 1), inclusive.
  • age will be between 1 and 17, inclusive.
  • digit will be between 0 and 9, inclusive.
Examples
0)
2048
3
0
Returns: 3000

The next number with exactly three zeros is 3000.

1)
47
9
2
Returns: 222222222
2)
9232425262
2
6
Returns: 9232425266
3)
7
1
2
Returns: 12
4)
99999999999999999
17
9
Returns: 199999999999999999
212)
76
1
7
Returns: 78

The next number with exactly one digit 7 is the number 78.

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

Coding Area

Language: C++17 · define a public class NextLuckyNumber with a public method long long getTicket(long long lastTicket, int age, int digit) · 213 test cases · 2 s / 256 MB per case

Submitting as anonymous