TopcoderArchiveVisit Topcoder
TCO30 Oct 2018
TCO19 SRM 741

DigitStringDiv2

Problem statement, definition, constraints, and public examples.

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.

Definition

Class:
DigitStringDiv2
Method:
count
Parameters:
String, int
Returns:
int
Method signature:
int count(String S, int X)
(be sure your method is public)

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.

Examples

  1. "0"
    1
    Returns: 0
  2. "10"
    9
    Returns: 1
  3. "471"
    47
    Returns: 2
    We can select either the substring "471" or the substring "71".
  4. "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
Back to all problems