Connection Status:
Competition Arena > Top5
SRM 112 · 2002-09-06 · by dgoodman
Class Name: Top5
Return Type: String
Method Name: topNames
Arg Types: (vector<int>, vector<string>)
Problem Statement

Problem Statement

We are reviewing applications for a job. Each applicant has taken a test, and we want to restrict our attention to the top 5 applicants according to their scores. Create a class Top5 that contains the method topNames that takes the scores and the names of the applicants as inputs and returns the names of the top 5 applicants (plus ties).

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
Examples
0)
{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.

1)
{3}
{"Stickberger"}
Returns: "Stickberger"
2)
{1,1,8,1,8,1,1}
{"Y","T","R","E","W","Q","QQ"}
Returns: "Y, T, R, E, W, Q, QQ"
3)
{8,8,8,8,8,9}
{"a","b","c","d","e","f"}
Returns: "a, b, c, d, e, f"
4)
{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.

Coding Area

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

Submitting as anonymous