Advertisement
smatskevich

Seminar2

Sep 26th, 2022
902
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.92 KB | None | 0 0
  1. #include <algorithm>
  2. #include <iostream>
  3. #include <vector>
  4.  
  5. void Erase(std::vector<int>& v, int to_erase) {
  6.   int j = 0;
  7.   for (int i = 0; i < v.size(); i++) {
  8.     if (v[i] != to_erase) {
  9.       v[j++] = v[i];
  10.     }
  11.   }
  12.   v.erase(v.begin() + j, v.end());
  13. }
  14.  
  15. void Print(const std::vector<int>& v) {
  16.   for (int i = 0; i < v.size(); ++i) {
  17.     std::cout << v[i] << " ";
  18.   }
  19.   std::cout << std::endl;
  20. }
  21.  
  22. int main0() {
  23.   int n = 0;
  24.   std::cin >> n;
  25.  
  26.   std::vector<int> v(n);
  27.   for (int i = 0; i < n; ++i) {
  28.     std::cin >> v.operator[](i);
  29.   }
  30.   int to_erase = 0;
  31.   std::cin >> to_erase;
  32.   Erase(v, to_erase);
  33.   Print(v);
  34.   return 0;
  35. }
  36.  
  37. int main() {
  38.   int n = 0;
  39.   std::cin >> n;
  40.  
  41.   std::vector<int> v(n);
  42.   for (int i = 0; i < n; ++i) {
  43.     std::cin >> v[i];
  44.   }
  45.  
  46.   std::vector<int>::iterator it = std::lower_bound(v.begin(), v.end(), 5);
  47.   std::cout << it - v.begin() << std::endl;
  48.  
  49.   return 0;
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement