Advertisement
Glenpl

Untitled

Nov 14th, 2015
188
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.65 KB | None | 0 0
  1. #include <iostream>
  2. #include <set>
  3. #include <vector>
  4.  
  5. int main()
  6. {
  7.     std::vector<int> arr = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 0, 5, 3, 2, 1, 6, 8, 3, 2, 1 }; // najwieksze: 9, 8, 8
  8.     std::multiset<int> maxs = { arr[0], arr[1], arr[2] }; // trzy pierwsze elementy
  9.  
  10.     for (auto it = arr.begin() + 2; it != arr.end(); ++it) {
  11.         if (*it > *maxs.begin()) // aktualna wartosc jest wieksza od najmniejszego elementu w maxs
  12.         {
  13.             maxs.erase(maxs.begin()); // usun najmniejsza wartosc
  14.             maxs.insert(*it); // dodaj aktualna wartosc it
  15.         }
  16.     }
  17.  
  18.     for (auto x : maxs)
  19.         std::cout << x << "\n";
  20.     return 0;
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement