Problem Statement
Two lines (or queues) of people often have to merge into a single-file line. But, chivalry is not dead! When a man and a woman are about to merge, the man will always let the woman go first.
Given two lines of both men and women, write a method getOrder which will determine the genders of the people in the final line. If two women are at the front of both lines, the woman from the first line goes first. Likewise, if two men are at the front of both lines, the man from the first line goes first. Then, the people at the front of both lines are compared again.
Each input line will be a
Definition
- Class:
- Chivalry
- Method:
- getOrder
- Parameters:
- String, String
- Returns:
- String
- Method signature:
- String getOrder(String first, String second)
- (be sure your method is public)
Constraints
- first and second will each be between 1 and 50 characters long, inclusive.
- first and second will consist of the characters 'M' and 'W' only.
Examples
"M"
"W"
Returns: "WM"
"MM"
"MW"
Returns: "MMMW"
Because of the 'tie breaker' rules, the first man from the first line goes first. Then, the second man from the first line goes, then the rest of the people (both from the second line.)
"MMMM"
"W"
Returns: "WMMMM"
"M"
"WWW"
Returns: "WWWM"
"MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMW"
"WMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM"
Returns: "WMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMWMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM"
"MMMMMWWWW"
"MWWWW"
Returns: "MMMMMWWWWMWWWW"
"MWWWW"
"MMMMMWWWW"
Returns: "MWWWWMMMMMWWWW"
"WMW"
"WMW"
Returns: "WWMWMW"
"WWWW"
"WWWW"
Returns: "WWWWWWWW"
"MMMM"
"W"
Returns: "WMMMM"
"W"
"MMMM"
Returns: "WMMMM"
"MMMMMMMMMMWWWWWWWWWWMMMMMMMMMMWWWWWWWWWWMMMMMMMMMM"
"WWWWWWWWWWMMMMMMMMMMWWWWWWWWWWMMMMMMMMMMWWWWWWWWWW"
Returns: "WWWWWWWWWWMMMMMMMMMMWWWWWWWWWWMMMMMMMMMMWWWWWWWWWWMMMMMMMMMMMMMMMMMMMMWWW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