Statistics

Problem Statement for "Quipu"

Problem Statement

The Incas used a sophisticated system of record keeping consisting of bundles of knotted cords. Such a bundle of cords is called a quipu. Each individual cord represents a single number. Surprisingly, the Incas used a base-10 positional system, just like we do today. Each digit of a number is represented by a cluster of adjacent knots, with spaces between neighboring clusters. The digit is determined by the number of knots in the cluster. For example, the number 243 would be represented by a cord with knots tied in the following pattern

     -XX-XXXX-XXX-
where each uppercase 'X' represents a knot and each '-' represents an unknotted segment of cord (all quotes for clarity only).

Unlike many ancient civilizations, the Incas were aware of the concept of zero, and used it in their quipus. A zero is represented by a cluster containing no knots. For example, the number 204003 would be represented by a cord with knots tied in the following pattern

     -XX--XXXX---XXX-
        ^^    ^^^
        ^^    ^^^
        ^^    two zeros between these three segments
        ^^
        one zero between these two segments
Notice how adjacent dashes signal the presence of a zero.

Your task is to translate a single quipu cord into an integer. The cord will be given as a String knots containing only the characters 'X' and '-'. There will be a single '-' between each cluster of 'X's, as well as a leading '-' and a trailing '-'. The first cluster will not be empty.

Definition

Class:
Quipu
Method:
readKnots
Parameters:
String
Returns:
int
Method signature:
int readKnots(String knots)
(be sure your method is public)

Constraints

  • knots contains between 3 and 50 characters, inclusive.
  • knots contains only the characters 'X' and '-'. Note that 'X' is uppercase.
  • The first and last characters of knots are '-'s. The second character is 'X'.
  • knots does not contain 10 consecutive 'X's.
  • knots will represent a number between 1 and 1000000, inclusive.

Examples

  1. "-XX-XXXX-XXX-"

    Returns: 243

    The first example above.

  2. "-XX--XXXX---XXX-"

    Returns: 204003

    The second example above.

  3. "-X-"

    Returns: 1

  4. "-XX-"

    Returns: 2

  5. "-XXX-"

    Returns: 3

  6. "-XXXX-"

    Returns: 4

  7. "-XXXXX-"

    Returns: 5

  8. "-XXXXXX-"

    Returns: 6

  9. "-XXXXXXX-"

    Returns: 7

  10. "-XXXXXXXX-"

    Returns: 8

  11. "-XXXXXXXXX-"

    Returns: 9

  12. "-X-------"

    Returns: 1000000

  13. "-XXXXXXXXX--XXXXXXXXX-XXXXXXXXX-XXXXXXX-XXXXXXXXX-"

    Returns: 909979

  14. "-XX-XXXXX-"

    Returns: 25

  15. "-XXXXXX-X-"

    Returns: 61

  16. "-XXXXXXXX-XXX-"

    Returns: 83

  17. "-XX-XXXXXXXXX-XXXXXXXX-XXX---"

    Returns: 298300

  18. "-XXXX-XXXXX-XX-X-XXXX--"

    Returns: 452140

  19. "-XXXXXX-XXXX-XXXXXXXX-XXXXXXXX--XXX-"

    Returns: 648803

  20. "-XXXXXXX-XXXXXXXXX-XXXXXXXXX-XXXXX-XXXXXXXXX-X-"

    Returns: 799591

  21. "-XXXXXXXX-XXXXXXXX--XXXXXX-XXXXXXXXX-XXX-"

    Returns: 880693

  22. "-X-XXXX-XXXXXXXX-XXXXX-XXXXX-XX-"

    Returns: 148552

  23. "-XXXX-XXXXXXXXX-XXXXX-XXXXXXXX-XXXXXXXX-XXXXXX-"

    Returns: 495886

  24. "-XXX-XXXXXX--XX-XX-XXXXX-"

    Returns: 360225

  25. "-XXXXX-XXXXXXXX-XXXXXXXX-XXX-"

    Returns: 5883

  26. "-XXXX-XXXXX-X-XXXXXXX-XXXXXXX-XXX-"

    Returns: 451773

  27. "-XXXXXXX-XX--XXXXXXXXX---"

    Returns: 720900

  28. "-XXXXXXXXX-XXXXXXX-XXXXXXXX-XXX-XXXX-XXXXX-"

    Returns: 978345

  29. "-X-XXXXXXXX-X-XX-XXXXXXXXX-XXXXX-"

    Returns: 181295

  30. "-XXXXX-X-XX-XXXXX-XXXXX-XXX-"

    Returns: 512553

  31. "-XXXX-X-XXXX-XXXX-X-XXXXX-"

    Returns: 414415

  32. "-XXXXXX-XXXXXXXX-XX-XXXXXXXX-XXXXXXX-XXXXX-"

    Returns: 682875

  33. "-XXX--XXXXXXXX-XXXXXX-XXXXXXXX-XXXX-"

    Returns: 308684

  34. "-X-XXXXXXXXX--XXXXX-XXXXXXX-"

    Returns: 19057

  35. "-XXXXXXX-XXXXX-XX-X-XXXXX-XXXXXXXX-"

    Returns: 752158

  36. "-XXXXXXXXX-XXXX-XXX--X-XX-"

    Returns: 943012

  37. "-X-----"

    Returns: 10000

  38. "-XX--"

    Returns: 20


This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2024, TopCoder, Inc. All rights reserved.
This problem was used for: