Advertisement
MathQ_

Untitled

May 1st, 2021
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.69 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <algorithm>
  4. #include <numeric>
  5. #include <random>
  6.  
  7. using namespace std;
  8.  
  9. random_device rd;
  10. mt19937 g(rd());
  11.  
  12. void remove(vector<int> &a) {
  13.     for (int i = 0; i < a.size(); ++i) {
  14.         if (a[i] & 1) {
  15.             a.erase(a.begin() + i);
  16.             --i;
  17.         }
  18.     }
  19. }
  20.  
  21. void print(vector<int> &a) {
  22.     for (auto el : a) {
  23.         cout << el << " ";
  24.     }
  25. }
  26.  
  27. int no_in_vector(int x) {
  28.     return x;
  29. }
  30.  
  31. int main() {
  32.     const int n = 50;
  33.     vector<int> a(n);
  34.     int x = rd() % (n + 1);
  35.     iota(a.begin(), a.end(), 0);
  36.     for (int i = x; i < n; ++i) ++a[i];
  37.     shuffle(a.begin(), a.end(), g);
  38.     cout << no_in_vector(x) << '\n';
  39.     remove(a);
  40.     print(a);
  41.     return 0;
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement