diff --git a/cpp/README.md b/cpp/README.md index 38c31fe0..dc1b3fef 100644 --- a/cpp/README.md +++ b/cpp/README.md @@ -48,7 +48,7 @@ These two sources are widely considered to be the best sources. Studying, and contributing to, open source projects is an excellent way to improve your proficiency in any language. Here is just a tiny sampling the thousands of projects featuring C++: - [TensorFlow](https://github.com/tensorflow/tensorflow) -- [React Electron](https://github.com/electron/electron) +- [Electron](https://github.com/electron/electron) - [Godot](https://github.com/godotengine/godot) - [Google Test](https://github.com/google/googletest) - [ClickHouse](https://github.com/ClickHouse/ClickHouse) diff --git a/cpp/top_ten_scorers.cpp b/cpp/top_ten_scorers.cpp index fc8c6fd8..79601c4f 100644 --- a/cpp/top_ten_scorers.cpp +++ b/cpp/top_ten_scorers.cpp @@ -6,40 +6,40 @@ #include struct Player { - std::string name; - std::string team; - double ppg; + std::string name; + std::string team; + double ppg; }; int main() { - std::vector players; + std::vector players; - std::string line; - while (std::getline(std::cin, line)) { - std::stringstream ss(line); - std::string team, name, games, points; - std::getline(ss, team, ','); - std::getline(ss, name, ','); - std::getline(ss, games, ','); - std::getline(ss, points, ','); - int gamesInt = std::stoi(games); - if (gamesInt >= 15) { - double ppg = static_cast(std::stoi(points)) / gamesInt; - players.push_back({name, team, ppg}); - } + std::string line; + while (std::getline(std::cin, line)) { + std::stringstream ss(line); + std::string team, name, games, points; + std::getline(ss, team, ','); + std::getline(ss, name, ','); + std::getline(ss, games, ','); + std::getline(ss, points, ','); + int gamesInt = std::stoi(games); + if (gamesInt >= 15) { + double ppg = static_cast(std::stoi(points)) / gamesInt; + players.push_back({name, team, ppg}); } + } - // Sort and print the top 10 players by PPG - std::partial_sort( - players.begin(), players.begin() + 10, players.end(), - [](const Player& a, const Player& b) { return a.ppg > b.ppg; } - ); + // Sort and print the top 10 players by PPG + std::partial_sort( + players.begin(), players.begin() + 10, players.end(), + [](const Player& a, const Player& b) { return a.ppg > b.ppg; } + ); - for (const Player& player : std::vector(players.begin(), players.begin() + 10)) { - std::cout - << std::left << std::setw(22) << player.name - << std::left << std::setw(4) << player.team - << std::right << std::fixed << std::setprecision(2) << std::setw(8) << player.ppg - << std::endl; - } + for (const Player& player : std::vector(players.begin(), players.begin() + 10)) { + std::cout + << std::left << std::setw(22) << player.name + << std::left << std::setw(4) << player.team + << std::right << std::fixed << std::setprecision(2) << std::setw(8) << player.ppg + << std::endl; + } }