Advertisement
Spocoman

03. Numbers

Nov 7th, 2023 (edited)
522
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.84 KB | None | 0 0
  1. #include <iostream>
  2. #include <sstream>
  3. #include <string>
  4. #include <vector>
  5. #include <algorithm>
  6.  
  7. using namespace std;
  8.  
  9. int main() {
  10.     int number, sumNumbers = 0;
  11.  
  12.     string line;
  13.     getline(cin, line);
  14.  
  15.     istringstream stream(line);
  16.  
  17.     vector<int> numbers;
  18.  
  19.     while (stream >> number) {
  20.         numbers.push_back(number);
  21.         sumNumbers += number;
  22.     }
  23.  
  24.     numbers.erase(remove_if(numbers.begin(), numbers.end(), [&](const int& i) {
  25.         return i <= ((double)sumNumbers / numbers.size());
  26.         }), numbers.end());
  27.  
  28.     sort(numbers.begin(), numbers.end(), greater<int>());
  29.  
  30.     if (numbers.size() == 0) {
  31.         cout << "No" << endl;
  32.     }
  33.     else {
  34.         for (int i = 0; i < (numbers.size() < 5? numbers.size() : 5); i++) {
  35.             cout << numbers[i] << ' ';
  36.         }
  37.     }
  38.     return 0;
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement