Connection Status:
Competition Arena > Losers
SRM 87 · 2002-05-09 · by insomnia
Class Name: Losers
Return Type: String[]
Method Name: find
Arg Types: (vector<string>)
Problem Statement

Problem Statement

You are playing a series of games. You want to find out who the worst player (or players) is.

Create a class Losers that contains a method find which, given a String[] games that lists all of the players of all of the games that have been played so far, returns the name of the worst player (or players if there is a tie). If more than one player ties for the worst, return all players that tie for the worst, sorted alphabetically. Each element will be a space-separated list of names of players that played that game - ordered by how they placed (1st place is listed 1st, 2nd place is listed 2nd, etc...). You compare players by counting their total score. Their scores are determined by the number of top-3 places they have accumulated. A second place is worth half as much as a win, and a 3rd place is worth 1/3 as much as a win. The player(s) with the lowest total score is the worst.

Notes

  • Not all players play each game. A player who does not play in a game gets no score for that game. You need to consider ALL players who have played in at least 1 of the games.

Constraints

  • games will contain between 1 and 50 elements, inclusive.
  • Valid player names will each be between 1 and 10 capital letters ('A' - 'Z'), inclusive.
  • Each element of games will contain at least one name, but need not have more than one player - there need not be a second or third place player.
  • Each element of games will be between 1 and 50 characters in length, inclusive.
  • Each element of games will be a list of 1 or more valid player names separated by single spaces, with no leading or trailing spaces.
  • Each element of games will contain no duplicate names.
  • There will not be more than 100 different player names total.
Examples
0)
{"BOB FRANK AMY", "BOB AMY FRANK"}
Returns: { "AMY",  "FRANK" }

Since BOB has two first places, his score is higher than each of the other two. AMY and FRANK each scored one second place and one third, so they have the same score - and are tied for the worst. Remember to sort the names alphabetically - AMY before FRANK.

1)
{"BOB MIKE DAVE FRANK ART"}
Returns: { "ART",  "FRANK" }

Since neither FRANK or ART ever placed in the top 3, they both tie for the worst score. Again, don't forget to sort the names alphabetically.

2)
{"BOB FRANK MIKE JOE ROB"}
Returns: { "JOE",  "ROB" }
3)
{"MIKEY DAVE", "DAVE MIKEY"}
Returns: { "DAVE",  "MIKEY" }
4)
{"MIKE", "ROB", "AMY"}
Returns: { "AMY",  "MIKE",  "ROB" }
6)
{"MIKE ROB AMY", "ROB AMY", "ROB AMY"}
Returns: { "MIKE" }

ROB and AMY each have total scores higher than MIKE.

7)
{"A B C", "D B C", "E D C"}
Returns: { "A",  "B",  "C",  "E" }

A and E each have one first place, B has 2 second places, and C has 3 third places - each totalling the same score, and D has a higher score than all the rest of them.

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

Coding Area

Language: C++17 · define a public class Losers with a public method vector<string> find(vector<string> games) · 36 test cases · 2 s / 256 MB per case

Submitting as anonymous