64 - The 8th Zhejiang University Programming Contest - 1007
Golf is a sport in which a player, using several types of clubs, hits a ball
into each hole on the golf course in the lowest possible number of strokes.
In a golf tournament, several players play on the same course simultaneously and separately, and their scores are recorded for each hole. It does not matter how long it takes you to finish all the holes, only the total score you get from all the holes matters. So when you're playing the 4th hole, someone may just start to play the first hole, while another one may have finished all the nine holes. For this reason, the rank list of golf is somewhat different from those in other games: players are ranked even though they're playing different holes. The rank list contains all the statistics of the players and is updated every time a player finishes a hole. Your task here is to read the information of a golf course, together with the strokes made by different players to finish each hole in order, print the current rank list on demand.
Standard input will contain multiple test cases. The first line of the input is a single integer T (1 <= T <= 150) which is the number of test cases. And it will be followed by T consecutive test cases.
Each test case represents a golf tournament and begins with a line with a positive integer H, the number of holes in this course (H <= 18). The second line contains H integers Pi, the par of each hole in the course (3 <= Pi <= 5, 1 <= i <= H). Then follow several lines with either the format "Name Strokes" or a string "ShowRank". A line with the format "Name Strokes" indicates the player Name has just finished a hole with Strokes strokes, where Name is the name of this player with no more than 10 letters (won't be "ShowRank"), and Strokes is a positive integer less than 10. A line with a string "EndOfTournament" indicates the end of this tournament. You may assume all players appear before will finish (exactly) all the H holes by then, and at most 100 players will participate in a tournament.
There's an empty line between every two contiguous cases as well as between T and the first test case.
For each tournament, print a line of "Tournament K" at the beginning, where K is the number of this tournament (starts from 1).
For each "ShowRank" string, you should print the current rank list with the following format:
1234567890123456789012345678901 Place Name Score Holes
The first column contains the places of players ranked according to their scores at present (while players with the same score will share the same place, of course); the second column contains the names of players; the third column contains the scores of players at present; and the last column contains the number of holes players have finished (except when a player has finished all the holes, use 'F' instead of the number of holes). The four columns take 5, 10, 5 and 5 spaces of characters, respectively, while there're two blank spaces between every two adjacent columns. (Just as the digits in the first row show and those digits will not be in the actual output) Places, scores and holes of players should be right aligned to the 5th, 24th and 31st characters, respectively, while names of players should be left aligned to the 8th character. Print a blank line after each rank list. (Refer to the sample output)
The players should be sorted by their scores in ascending order. Players with the same score should be sorted by their average scores among the holes they played in ascending order. (This also shows the chance of win for those players, since when two players have the same negative score, the one who has finished less holes is likely to win when he finishes all the holes, vice versa.) For the players with the same score and the same average score, just sort them with their names alphabetically.
1 3 4 5 3 Alpha 3 Bravo 5 ShowRank Charlie 4 Charlie 3 Bravo 4 Charlie 2 ShowRank Alpha 4 Alpha 2 Bravo 3 ShowRank EndOfTournament
Tournament 1 Place Name Score Holes 1 Alpha -1 1 2 Bravo +1 1 Place Name Score Holes 1 Charlie -3 F 2 Alpha -1 1 3 Bravo 0 2 Place Name Score Holes 1 Alpha -3 F 1 Charlie -3 F 3 Bravo 0 F