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.)
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
"..-..-"
Returns: "-.-..."
"-.-"
Returns: "-.-"
"--..-.---..--"
Returns: "--.--.---.-.."
"--..-.---..--..-----.--."
Returns: "--.--.--.-----.---.-...."
"..."
Returns: "..."