-
楼主 / voice
- 时间: 2008-11-07 12:52
-
-
第 2 楼 / webdriver
- 时间: 2008-11-07 12:55
gettext 写道:
请先把题抄下来, 半小时之后我会删掉。
问题说明
你需要对一组学生(男女生都有),进行从高到低排队,同时要求男女生间隔着。
输入:你将得到用一个数组(vector<string>存储的学生信息,每个学生信息为“name height sex”,height是一个整数,单位cm; sex为性别,可以为 "boy" 或者 "girl" 之一。
返回:返回一个字符串,包含用“-”连接起来的排序后的每个学生的名字。如果存在多个可能结果,则选择按照字母顺序最优的解。如果无解,返回空串。
Class:
StudentsOrdering
Method:
findOrder
Parameters:
vector <string>
Returns:
string
Method signature:
string findOrder(vector <string> students)
(be sure your method is public)
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"
外?这下你删不掉了啵
-
-
第 3 楼 / myversa
- 时间: 2008-11-07 12:56
-
第 4 楼 / voice
- 时间: 2008-11-07 13:04
-
第 5 楼 / SARS
- 时间: 2008-11-07 13:08
-
第 6 楼 / 许万克
- 时间: 2008-11-07 13:15
-
第 7 楼 / SARS
- 时间: 2008-11-07 13:18
-
第 8 楼 / webdriver
- 时间: 2008-11-07 13:22
-
第 9 楼 / voice
- 时间: 2008-11-07 13:44
-
第 10 楼 / webdriver
- 时间: 2008-11-07 13:54