Advertisement
CR7CR7

TropheyPesho

Apr 6th, 2023
811
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.65 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <algorithm>
  4. using namespace std;
  5.  
  6. int main() {
  7.     // Read the number of trophies and their ranks
  8.     int n;
  9.     cin >> n;
  10.     vector<int> ranks(n);
  11.     for (int i = 0; i < n; i++) {
  12.         cin >> ranks[i];
  13.     }
  14.    
  15.     // Get the maximum rank
  16.     int max_rank = ranks[n-1];
  17.    
  18.     // Calculate the thresholds for each shelf
  19.     int shelf1 = max_rank * 0.9;
  20.     int shelf2 = max_rank * 0.5;
  21.     int shelf3 = max_rank * 0.2;
  22.    
  23.     // Create vectors to store the trophies for each shelf
  24.     vector<int> trophies1, trophies2, trophies3, trophies4;
  25.    
  26.     // Loop through the ranks and assign them to the appropriate shelf
  27.     for (int rank : ranks) {
  28.         if (rank > shelf1) {
  29.             trophies1.push_back(rank);
  30.         } else if (rank > shelf2) {
  31.             trophies2.push_back(rank);
  32.         } else if (rank > shelf3) {
  33.             trophies3.push_back(rank);
  34.         } else {
  35.             trophies4.push_back(rank);
  36.         }
  37.     }
  38.    
  39.     // Reverse the order of the trophies to print them in descending order
  40.     reverse(trophies1.begin(), trophies1.end());
  41.     reverse(trophies2.begin(), trophies2.end());
  42.     reverse(trophies3.begin(), trophies3.end());
  43.     reverse(trophies4.begin(), trophies4.end());
  44.    
  45.     // Print the output for each shelf
  46.     for (vector<int> trophies : {trophies1, trophies2, trophies3, trophies4}) {
  47.         if (trophies.empty()) {
  48.             cout << "empty" << endl;
  49.         } else {
  50.             for (int rank : trophies) {
  51.                 cout << rank << " ";
  52.             }
  53.             cout << endl;
  54.         }
  55.     }
  56.    
  57.     return 0;
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement