Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <algorithm>
- using namespace std;
- int main() {
- // Read the number of trophies and their ranks
- int n;
- cin >> n;
- vector<int> ranks(n);
- for (int i = 0; i < n; i++) {
- cin >> ranks[i];
- }
- // Get the maximum rank
- int max_rank = ranks[n-1];
- // Calculate the thresholds for each shelf
- int shelf1 = max_rank * 0.9;
- int shelf2 = max_rank * 0.5;
- int shelf3 = max_rank * 0.2;
- // Create vectors to store the trophies for each shelf
- vector<int> trophies1, trophies2, trophies3, trophies4;
- // Loop through the ranks and assign them to the appropriate shelf
- for (int rank : ranks) {
- if (rank > shelf1) {
- trophies1.push_back(rank);
- } else if (rank > shelf2) {
- trophies2.push_back(rank);
- } else if (rank > shelf3) {
- trophies3.push_back(rank);
- } else {
- trophies4.push_back(rank);
- }
- }
- // Reverse the order of the trophies to print them in descending order
- reverse(trophies1.begin(), trophies1.end());
- reverse(trophies2.begin(), trophies2.end());
- reverse(trophies3.begin(), trophies3.end());
- reverse(trophies4.begin(), trophies4.end());
- // Print the output for each shelf
- for (vector<int> trophies : {trophies1, trophies2, trophies3, trophies4}) {
- if (trophies.empty()) {
- cout << "empty" << endl;
- } else {
- for (int rank : trophies) {
- cout << rank << " ";
- }
- cout << endl;
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement