TopcoderArchiveVisit Topcoder
SRM11 Feb 2003
SRM 135

Plates

Problem statement, definition, constraints, and public examples.

Problem Statement

Recently all cars in NJ had a specific pattern of digits and letters for their license plate numbers. For example, the license plate number "UG830H" follows the pattern "LLDDDL", where 'L' stands for letter, and 'D' stands for digit. 17,576,000 distinct license plate numbers can be generated using this format. As the population and the number of cars grows, new formats appear. For example, the new format in NJ is "LLLDDL" (as in "MEL87H"). The new format will be able to number 45,697,600 cars. Assume that plates are assigned in lexicographic order (the order they would appear in a dictionary. i.e. "AAA" comes before "AAB" and "AA1" comes before "AA7"). For practical purposes it is important to know how many plates are available for further assignment at each moment in time.

Your task is, given a String representing a license plate number, return the total number of possible license plates following the same pattern as the input that can be assigned after the given plate number.

For example, given the String "D43", we must count all of the plate numbers that have one letter, followed by two digits, and come after "D43". Any sequence that starts with a letter after 'D' works (there are 100*22 of these), as does any sequence that starts with the letter 'D' and is followed by a two digit number greater than "43" (there are 56 of these).

Definition

Class:
Plates
Method:
numLeft
Parameters:
String
Returns:
long
Method signature:
long numLeft(String plateNum)
(be sure your method is public)

Notes

  • We assume that only upper-case letters and digits can be used in plate numbers.
  • Digit 0 (zero) should be treated like any other digit. That is, the plate number can start with 0, if it starts with a digit.
  • The 64 bit datatype in C++ is long long.

Constraints

  • plateNum contains between 3 and 8 characters inclusive
  • each character of plateNum is a digit ('0'-'9') or an upper-case letter ('A'-'Z')

Examples

  1. "222"
    Returns: 777
    plates are made of three digits starting from "000" and ending with "999".
  2. "TA4KA"
    Returns: 1227355
  3. "KAPETA"
    Returns: 189835177
  4. "MAPA3M"
    Returns: 63875149
  5. "ZZZZZ"
    Returns: 0
  6. "D43"
    Returns: 2256
Back to all problems