Top5
SRM 112 · 2002-09-06 · by dgoodman
Problem Statement
There will be more than 5 names returned if the 6th highest score is tied with the 5th highest score. There will be less than 5 names returned if there are fewer than 5 applicants. The return should list the top applicants in the order in which they applied (the order in which they appear in the inputs). Every two adjacent names in the return should be separated by a comma and space.
Notes
- the first score correponds to the first name, the second to the second, etc.
Constraints
- score and name contain the same number of elements
- the number of elements is between 1 and 50 inclusive
- each element of score is between 1 and 1000 inclusive
- each element of name contains only letters
- each element of name contains between 1 and 20 characters inclusive
- the elements of name are distinct
{5,5,7,2,8,3}
{"a","z","X","A","Tom","Jim"}
Returns: "a, z, X, Tom, Jim"
The score of 2 is not in the top 5, so A is eliminated.
{3}
{"Stickberger"}
Returns: "Stickberger"
{1,1,8,1,8,1,1}
{"Y","T","R","E","W","Q","QQ"}
Returns: "Y, T, R, E, W, Q, QQ"
{8,8,8,8,8,9}
{"a","b","c","d","e","f"}
Returns: "a, b, c, d, e, f"
{8,8,8,8,8,7}
{"a","b","c","d","e","f"}
Returns: "a, b, c, d, e"
Submissions are judged against all 12 archived test cases, of which 5 are shown here. Case numbers match the judge’s.
Language: C++17 · define a public class Top5 with a public method string topNames(vector<int> score, vector<string> name) · 12 test cases · 2 s / 256 MB per case