DigitStringDiv2
TCO19 SRM 741 · 2018-10-30 · by Blue.Mary
Problem Statement
You are given a digit string S and a positive integer integer X. We want to select a non-empty contiguous substring of S such that:
- The substring does not begin with the digit '0'.
- When you convert it to a number, its value is strictly greater than X.
Two ways of selecting a substring are different if they begin or end at a different index.
Compute and return the number of ways in which we can select a substring with the above properties.
Constraints
- S will contain between 1 and 9 characters, inclusive.
- Each character of S will be a digit ('0'-'9').
- X will be between 0 and 777,444,111, inclusive.
"0" 1 Returns: 0
"10" 9 Returns: 1
"471" 47 Returns: 2
We can select either the substring "471" or the substring "71".
"0" 777444111 Returns: 0
"000000000" 777444111 Returns: 0
"2222" 97 Returns: 3
We can select the entire string S ("2222"). We also have two different ways to select the string "222": either we choose the first three or the last three characters of S
Submissions are judged against all 40 archived test cases, of which 6 are shown here. Case numbers match the judge’s.
Language: C++17 · define a public class DigitStringDiv2 with a public method int count(string S, int X) · 40 test cases · 2 s / 256 MB per case