Advertisement
DiaxPlayer

Untitled

Feb 11th, 2017
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.86 KB | None | 0 0
  1. #include <iostream>
  2. #include <algorithm>
  3. #include <array>
  4. #include <random>
  5.  
  6. using uint = unsigned int;
  7.  
  8. int main()
  9. {
  10.     std::array<uint, 30> tab;
  11.     for (auto i = 0u; i < 30; ++i) {
  12.         tab[i] = i+10;
  13.     }
  14.  
  15.     // na czysto
  16.     std::copy(tab.begin(), tab.end(), std::ostream_iterator<uint>(std::cout, " "));
  17.     std::cout << std::endl;
  18.  
  19.     std::mt19937 g(std::random_device{}());
  20.     std::shuffle(tab.begin(), tab.end(), g);
  21.  
  22.     // losowo
  23.     std::copy(tab.begin(), tab.end(), std::ostream_iterator<uint>(std::cout, " "));
  24.     std::cout << std::endl;
  25.  
  26.     std::partial_sort(tab.begin(), tab.begin()+10, tab.end(), [](uint a, uint b){return a>b;});
  27.  
  28.     // częściowo posortowane
  29.     std::copy(tab.begin(), tab.end(), std::ostream_iterator<uint>(std::cout, " "));
  30.     std::cout << std::endl;
  31.  
  32.     char x;
  33.     std::cin >> x;
  34.     return 0;
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement