3201 - CS2351_DS_2025Spring_HW5 Scoreboard

Time

2025/05/12 00:00:00 2025/05/26 23:59:00

Clarification

# Problem Asker Description Reply Replier Reply Time For all team

# Problem Pass Rate (passed user / total user)
14632 Basketball League Leaderboard

14632 - Basketball League Leaderboard   

Description

IMPORTANT UPDATE! 5/19

TESTCASES HAVE BEEN UPDATED. PLEASE USE THE FOLLOWING METHOD FOR COMPARISON TO PREVENT FLOATING POINT PRECISION ERROR :

#include <cmath>

const double EPS = 1e-9;
bool float_equal(double a, double b) {
    return fabs(a - b) < EPS;
}

You are tasked with creating a leaderboard for a basketball competition.

Each player’s performance is recorded after each match with the following statistics:

  • Points scored in the game
  • Rebounds in the game
  • Assists in the game
  • Fouls committed in the game

 

A player may play multiple matches, and each match's stats are recorded. You need to maintain and update the player's statistics across all matches. Once a player has completed their matches, you need to update their statistics (Points, Rebounds, Assists, and Fouls) and sort them according to different criteria based on the commands provided

.

Your job is to calculate the overall performance for each player based on their averages across all games. After that, you will need to sort the players according to the command provided:

  • "All": Sort players based on their overall performance across all statistics.
  • "Score": Sort players based on their average score.
  • "Rebound": Sort players based on their average rebounds.
  • "Assist": Sort players based on their average assists.
  • "Foul": Sort players based on their average fouls (from the least).

 

Scoring Formula:

The overall performance of each player is calculated using the following weighted sum formula:

Overall Performance (All)=((Total Points×0.5)+(Total Rebounds×0.3)+(Total Assists×0.2)-(Total Fouls×0.2))/Total Matches

NOTE: You must round it to the closest 2 decimal places.

Hint : Try to use setprecision()

You need to #include <iomanip>

Where:

  • Avg Points = Average points scored by the player across all their games.
  • Avg Rebounds = Average rebounds by the player across all their games.
  • Avg Assists = Average assists by the player across all their games.
  • Avg Fouls = Average fouls by the player across all their games (fewer fouls are better, hence the negative weight).

TEAM LEADERBOARD

For test case 8-10 there will be a team leaderboard system. Whereas each player will be assigned to a team and each team has a numerical ID.

And each team will be ranked by average score

Team Average Score = Total Players Average Performance / Total Number of Players

Your boss told you this is optional, but you know that your boss is mean and he will deduct your salary if you don't meet his expectation (8/10 score).

Incase of Tie, sort by team ID.

A hint from your ex-senior who got fired: Notice that we have a lot of information to sort and it's often updated, try to choose a suitable sorting method!

Input

  1. The first line contains an integer N (1 ≤ N ≤ 100000), representing the number of commands Each of the next N lines contains commands in the following format :

    All

    Score

    Rebound

    Assist

    Foul

    Team

    Play PlayerName T P R A F

  2. Where:
    • PlayerName is a string containing the player’s name (1 ≤ length of PlayerName ≤ 20).
    • T represents the player's team ID (Integer) 0 ≤ T ≤ 100.
    • P, R, A, and F are integers representing the player’s stats for a particular game. (1 ≤ Points, Rebounds, Assists ≤ 50; 0 ≤ Fouls ≤ 5). 
    • A player can play multiple matches, and stats for each match should be added to their total stats and divided by match played. After each match, the averages should be updated. 
    • All, Score, Rebound, Assist, Foul, Team is the command of which category to sort

 

IMPORTANT: You are not allowed to STL library in this homework.

Summary of Commands:

  • Play: Playername T P R A F : This command means the player has played a match and you need to update their overall stats.
  • All: This command sorts players based on their overall performance using the weighted sum formula, taking into account all the stats (points, rebounds, assists, fouls).
  • Score: This command sorts players by their average points scored across all games.
  • Rebound: This command sorts players by their average rebounds across all games.
  • Assist : Thus command sorts players by their average assists across all games.
  • Foul: This command sorts players by their average fouls, where fewer fouls are better.
  • Team: This command sorts the team by the team's average total player score.

Output

For each command, output the top 3 players/teams based on the sorting criteria.

  • If there are fewer than 3 players, output all players sorted by the command.
  • Players should be sorted in descending order by the specified criteria. In case of a tie, players should be sorted lexicographically by name.

For the "Foul" command, sort players in ascending order of fouls (fewer fouls are better).

Sample Input  Download

Sample Output  Download




Discuss