Skip to content

Commit

Permalink
Indentation
Browse files Browse the repository at this point in the history
  • Loading branch information
rtoal committed Apr 1, 2024
1 parent 3218ae7 commit efa2565
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 30 deletions.
2 changes: 1 addition & 1 deletion cpp/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
58 changes: 29 additions & 29 deletions cpp/top_ten_scorers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,40 +6,40 @@
#include <algorithm>

struct Player {
std::string name;
std::string team;
double ppg;
std::string name;
std::string team;
double ppg;
};

int main() {
std::vector<Player> players;
std::vector<Player> 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<double>(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<double>(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<Player>(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<Player>(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;
}
}

0 comments on commit efa2565

Please sign in to comment.