Connection Status:
Competition Arena > StudentsOrdering
TCCC06 Qual 1 · 2006-08-22 · by Andrew_Lazarev · Sorting, String Manipulation
Class Name: StudentsOrdering
Return Type: String
Method Name: findOrder
Arg Types: (vector<string>)
Problem Statement

Problem Statement

You want to arrange a group of students so that their heights are in non-descending order, and boys and girls alternate with each other.

You will be given a String[] students. Each element of students will be in the format "name height sex" (quotes for clarity only), where height is an integer in centimeters and sex is either "boy" or "girl" (quotes for clarity only). Return a String containing a dash-separated list of the students' names in the desired order. If multiple return values are possible, return the one that comes first lexicographically. If there is no possible ordering, return "" (empty String). Note that dashes ('-') come earlier lexicographically than letters.

Constraints

  • students will contain between 1 and 50 elements, inclusive.
  • Each element of students will be contain between 1 and 50 characters, inclusive.
  • Each element of students will be formatted as described in the problem statement.
  • The name of each student will consist of letters ('A'-'Z', 'a'-'z') only.
  • The height of each student will be between 100 and 250, inclusive.
  • The height of each student will contain no leading zeroes.
Examples
0)
{"Alex 180 boy", 
 "Josh 181 boy", 
 "Mary 158 girl", 
 "An 158 girl", 
 "Tanya 180 girl", 
 "Ted 158 boy"}
Returns: "An-Ted-Mary-Alex-Tanya-Josh"
1)
{"Alex 180 boy", 
 "Josh 158 boy", 
 "Mary 180 girl", 
 "An 158 girl", 
 "Mary 180 girl", 
 "Ted 158 boy"}
Returns: "Josh-An-Ted-Mary-Alex-Mary"

Student names can repeat.

2)
{"Alex 180 boy", 
 "Josh 170 boy", 
 "An 158 girl", 
 "Mary 180 girl", 
 "Ted 175 boy"}
Returns: ""

There is no girl to place between Josh and Ted.

3)
{"Mary 175 girl"}
Returns: "Mary"
4)
{"idaQrdoFlblpjgafvBqVWvXITSjqTBcrzBK 194 boy","idaQrdoFlblpjgafvBqVWvXITSjqTBcrzBK 129 boy","idaQrdoFlblpjgafvBqVWvXITSjqTBcrzBK 165 boy","idaQrdoFlblpjgafvBqVWvXITSjqTBcrzBK 161 girl","idaQrdoFlblpjgafvBqVWvXITSjqTBcrzBK 128 girl","tbDVhQqgfkfoVGKqhINzAHFkz 118 girl","idaQrdoFlblpjgafvBqVWvXITSjqTBcrzBK 150 boy","idaQrdoFlblpjgafvBqVWvXITSjqTBcrzBK 129 boy","tbDVhQqgfkfoVGKqhINzAHFkz 120 girl","idaQrdoFlblpjgafvBqVWvXITSjqTBcrzBK 208 boy","idaQrdoFlblpjgafvBqVWvXITSjqTBcrzBK 136 boy","idaQrdoFlblpjgafvBqVWvXITSjqTBcrzBK 144 girl","tbDVhQqgfkfoVGKqhINzAHFkz 119 boy","idaQrdoFlblpjgafvBqVWvXITSjqTBcrzBK 170 boy","idaQrdoFlblpjgafvBqVWvXITSjqTBcrzBK 184 boy","idaQrdoFlblpjgafvBqVWvXITSjqTBcrzBK 185 girl","idaQrdoFlblpjgafvBqVWvXITSjqTBcrzBK 154 girl","idaQrdoFlblpjgafvBqVWvXITSjqTBcrzBK 120 boy","idaQrdoFlblpjgafvBqVWvXITSjqTBcrzBK 199 girl","idaQrdoFlblpjgafvBqVWvXITSjqTBcrzBK 207 girl","idaQrdoFlblpjgafvBqVWvXITSjqTBcrzBK 179 boy","idaQrdoFlblpjgafvBqVWvXITSjqTBcrzBK 190 boy","idaQrdoFlblpjgafvBqVWvXITSjqTBcrzBK 145 boy","idaQrdoFlblpjgafvBqVWvXITSjqTBcrzBK 150 girl","tbDVhQqgfkfoVGKqhINzAHFkz 119 boy","idaQrdoFlblpjgafvBqVWvXITSjqTBcrzBK 185 girl","idaQrdoFlblpjgafvBqVWvXITSjqTBcrzBK 203 boy","idaQrdoFlblpjgafvBqVWvXITSjqTBcrzBK 179 girl","idaQrdoFlblpjgafvBqVWvXITSjqTBcrzBK 133 girl","idaQrdoFlblpjgafvBqVWvXITSjqTBcrzBK 195 boy","idaQrdoFlblpjgafvBqVWvXITSjqTBcrzBK 175 girl","idaQrdoFlblpjgafvBqVWvXITSjqTBcrzBK 175 boy","idaQrdoFlblpjgafvBqVWvXITSjqTBcrzBK 194 girl","idaQrdoFlblpjgafvBqVWvXITSjqTBcrzBK 138 girl","idaQrdoFlblpjgafvBqVWvXITSjqTBcrzBK 156 boy","idaQrdoFlblpjgafvBqVWvXITSjqTBcrzBK 142 boy","idaQrdoFlblpjgafvBqVWvXITSjqTBcrzBK 183 boy","idaQrdoFlblpjgafvBqVWvXITSjqTBcrzBK 125 girl","idaQrdoFlblpjgafvBqVWvXITSjqTBcrzBK 194 girl","idaQrdoFlblpjgafvBqVWvXITSjqTBcrzBK 181 girl","idaQrdoFlblpjgafvBqVWvXITSjqTBcrzBK 168 girl"}
Returns: ""

Submissions are judged against all 124 archived test cases, of which 5 are shown here. Case numbers match the judge’s.

Coding Area

Language: C++17 · define a public class StudentsOrdering with a public method string findOrder(vector<string> students) · 124 test cases · 2 s / 256 MB per case

Submitting as anonymous