Ropestring
SRM 696 · 2016-07-09 · by subscriber
SRM 696 · 2016-07-09 · by subscriber · String Manipulation
Problem Statement
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:
String that encodes it.
- 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.)
Constraints
- s will contain between 1 and 50 characters, inclusive.
- Each character in s will be either '-' or '.'.
Examples
0)
"..-..-" Returns: "-.-..."
1)
"-.-" Returns: "-.-"
2)
"--..-.---..--" Returns: "--.--.---.-.."
3)
"--..-.---..--..-----.--." Returns: "--.--.--.-----.---.-...."
4)
"..." Returns: "..."
Submissions are judged against all 78 archived test cases, of which 5 are shown here. Case numbers match the judge’s.
Coding Area
Language: C++17 · define a public class Ropestring with a public method string makerope(string s) · 78 test cases · 2 s / 256 MB per case