Statistics

Problem Statement for "Ropestring"

Problem Statement

Hero has a collection of ropes. You are given the String s that contains an ASCII art depicting this collection of ropes. Each character of s is either '-' (dash, ASCII 45) or '.' (period, ASCII 46). Each dash is a rope segment, each period is an empty space. Each contiguous segment of dashes represents one rope; the number of dashes is the length of the rope. For example, s = "..-..----." means that Hero has two ropes: one of length 1 and one of length 4. Hero has decided to rearrange his collection of ropes, using the following rules:
  • Each rope that has an even length must be placed to the left of all ropes that have odd lengths.
  • There must be at least one empty space between any two ropes.
  • If there are multiple arrangements that satisfy the previous two rules, Hero will choose the one that corresponds to the lexicographically smallest string. (This is explained below.)
Once Hero rearranges his ropes, we can encode their new placement into a new string that looks similar to s. (The string will have the same length as s and it will contain the same collection of ropes, but possibly in different places.) Given two strings of the same length, the lexicographically smaller one is the one that has a character with a smaller ASCII value on the first position on which they differ. For example, the string X = "---.-" is lexicographically smaller than the string Y = "-.---" because X[0] = Y[0] and X[1] &lt Y[1]. (Note that a dash has a smaller ASCII value than a period.) Construct the arrangement of ropes chosen by Hero and return the String that encodes it.

Definition

Class:
Ropestring
Method:
makerope
Parameters:
String
Returns:
String
Method signature:
String makerope(String s)
(be sure your method is public)

Constraints

  • s will contain between 1 and 50 characters, inclusive.
  • Each character in s will be either '-' or '.'.

Examples

  1. "..-..-"

    Returns: "-.-..."

  2. "-.-"

    Returns: "-.-"

  3. "--..-.---..--"

    Returns: "--.--.---.-.."

  4. "--..-.---..--..-----.--."

    Returns: "--.--.--.-----.---.-...."

  5. "..."

    Returns: "..."

  6. "...-.....-..--...-...--...-.......-.-....-"

    Returns: "--.--.-.-.-.-.-.-.-......................."

  7. "--------.-.-.--"

    Returns: "--------.--.-.-"

  8. "-----.----..--------------------------.--.-"

    Returns: "--------------------------.----.--.-----.-."

  9. ".--.---.---..-.-......-..-...-.-....."

    Returns: "--.---.---.-.-.-.-.-.-..............."

  10. "......................................."

    Returns: "......................................."

  11. "..............-.....-.---..-......------..-."

    Returns: "------.---.-.-.-.-.........................."

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

    Returns: "--.--.--.-.-.-.-......................."

  13. "-...----...."

    Returns: "----.-......"

  14. ".--.--.----.--.--.---.-------.-.-"

    Returns: "----.--.--.--.--.-------.---.-.-."

  15. "....-...-..........--.-.........-"

    Returns: "--.-.-.-.-......................."

  16. "-.---.-.-.-.--..-...--------.-------.-.-"

    Returns: "--------.--.-------.---.-.-.-.-.-.-.-..."

  17. "--."

    Returns: "--."

  18. "-.-.-..--.--.--.-----.--"

    Returns: "--.--.--.--.-----.-.-.-."

  19. "---...---.------.-"

    Returns: "------.---.---.-.."

  20. "-......-.....--.---."

    Returns: "--.---.-.-.........."

  21. "--.---------.---.-.---------"

    Returns: "--.---------.---------.---.-"

  22. "............."

    Returns: "............."

  23. "-.--------------------------"

    Returns: "--------------------------.-"

  24. "----------------------."

    Returns: "----------------------."

  25. "-------.--------.----.-------.---."

    Returns: "--------.----.-------.-------.---."

  26. "..-.-.-..--..-"

    Returns: "--.-.-.-.-...."

  27. "-----------------------"

    Returns: "-----------------------"

  28. "..-.--"

    Returns: "--.-.."

  29. "-------.------.------------..--.----------.---.--."

    Returns: "------------.----------.------.--.--.-------.---.."

  30. "----.--.----.------..-."

    Returns: "------.----.----.--.-.."

  31. "----.....-.-.-----.-----"

    Returns: "----.-----.-----.-.-...."

  32. "--------------------------------.-------------.--."

    Returns: "--------------------------------.--.-------------."

  33. "------"

    Returns: "------"

  34. "...-........--."

    Returns: "--.-..........."

  35. "............."

    Returns: "............."

  36. "..-.-----.--..----"

    Returns: "----.--.-----.-..."

  37. "...."

    Returns: "...."

  38. ".-.--.--.-----.--.---.----.--"

    Returns: "----.--.--.--.--.-----.---.-."

  39. "--------.--------."

    Returns: "--------.--------."

  40. "...-...-...-...-.....-.....-.--..............--.."

    Returns: "--.--.-.-.-.-.-.-................................"

  41. ".-...-...-...-....-.....-------..--.."

    Returns: "--.-------.-.-.-.-.-................."

  42. "..-........---."

    Returns: "---.-.........."

  43. "------.----.----------------------"

    Returns: "----------------------.------.----"

  44. "...--..-...--..-..-...-.......-.........--...-...."

    Returns: "--.--.--.-.-.-.-.-.-.............................."

  45. "....."

    Returns: "....."

  46. ".-..-...................-...-......."

    Returns: "-.-.-.-............................."

  47. ".--.-------.----..-"

    Returns: "----.--.-------.-.."

  48. "--..--.-...--....-..-.-..-.-"

    Returns: "--.--.--.-.-.-.-.-.-........"

  49. "--..-..--..-.-..---..---..------...--......"

    Returns: "------.--.--.--.---.---.-.-.-.............."

  50. "...................................."

    Returns: "...................................."

  51. "--------------------------------------------------"

    Returns: "--------------------------------------------------"

  52. "-....-.......-....-.......-..--.--...--.-.--.....-"

    Returns: "--.--.--.--.-.-.-.-.-.-.-........................."

  53. ".--.-------.-.-----.---.--.-.-.-.--."

    Returns: "--.--.--.-------.-----.---.-.-.-.-.."

  54. ".-.-.......-"

    Returns: "-.-.-......."

  55. "-..-......."

    Returns: "-.-........"

  56. ".........................................."

    Returns: ".........................................."

  57. "-.---.-------.---"

    Returns: "-------.---.---.-"

  58. "--.-----.-------.-.-..--.-.-.-.-.---.----.---..---"

    Returns: "----.--.--.-------.-----.---.---.---.-.-.-.-.-.-.."

  59. ".---...--.-....-----....-...-.-..----.--.--..---."

    Returns: "----.--.--.--.-----.---.---.-.-.-.-.............."

  60. "--------------------------------------------"

    Returns: "--------------------------------------------"

  61. "-------------.-----------.-.---.----"

    Returns: "----.-------------.-----------.---.-"

  62. "------"

    Returns: "------"

  63. "---.-------.------"

    Returns: "------.-------.---"

  64. "..--...--..."

    Returns: "--.--......."

  65. "..--..-.-.....-----.-..-.---..----.-...-.---.-"

    Returns: "----.--.-----.---.---.-.-.-.-.-.-.-..........."

  66. "..................-...-..."

    Returns: "-.-......................."

  67. "..-..-........--..--.-..---.-..-"

    Returns: "--.--.---.-.-.-.-.-............."

  68. "--.------------...---------------."

    Returns: "------------.--.---------------..."

  69. "..----.-.-.-.--..-.-----.-..------...-.---.-----.."

    Returns: "------.----.--.-----.-----.---.-.-.-.-.-.-........"

  70. "."

    Returns: "."

  71. "----.--.---."

    Returns: "----.--.---."

  72. "----"

    Returns: "----"

  73. "....--"

    Returns: "--...."

  74. ".----.--.------.-.---"

    Returns: "------.----.--.---.-."

  75. "-"

    Returns: "-"

  76. "----.--"

    Returns: "----.--"

  77. "....--...--------..------."

    Returns: "--------.------.--........"

  78. "--.--"

    Returns: "--.--"


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: