Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2019
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.46 KB | None | 0 0
  1. #include <vector>
  2. #include <iostream>
  3.  
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8.     vector<int> v1;
  9.     v1.push_back(1); v1.push_back(2); v1.push_back(3);
  10.  
  11.     //for (auto i : v1)cout << i << std::endl;
  12.     //for (auto it = v1.begin(); it < v1.end(); it++) cout << *it << std::endl;
  13.     //for (auto it = v1.end() - 1;  it >= v1.begin(); --it) cout << *it << std::endl;
  14.  
  15.     // Reverse operator
  16.     //for (auto it = v1.rbegin(); it < v1.rend(); it++) cout << *it << std::endl;
  17.     //for (vector<int>::reverse_iterator it = v1.rbegin(); it < v1.rend(); it++) cout << *it << std::endl;
  18.  
  19.     vector<int>::iterator it = v1.begin();
  20.     //cout << *it << *(it + 2);
  21.  
  22.     int i, j;
  23.     cout << "Input: "; cin >> i >> j;
  24.     //cout << *(it + i - 1);
  25.  
  26.     vector<int> v2;
  27.     for (auto it = v1.begin() + i - 1; it <= v1.begin() + j - 1; it++)
  28.     {
  29.         std::cout << *it << std::endl;
  30.         v2.push_back(*it);
  31.     }
  32.  
  33.     std::cout << std::endl;
  34.  
  35.     for (auto v : v2)
  36.         std::cout << v;
  37.  
  38.     std::cout << std::endl;
  39.  
  40.     vector<int> v3;
  41.     for (it = v1.begin(); it < v1.end() - 1; it++) v3.push_back(*it + *(it + 1));
  42.  
  43.     for (auto v : v3) std::cout << v << std::endl;
  44.  
  45.     std::cout << std::endl;
  46.     v1.insert(v1.begin(), 5, 5);
  47.     for (auto v : v1) std::cout << v << std::endl;
  48.  
  49.     std::cout << std::endl;
  50.     v1.erase(v1.begin(), v1.end() - 1);
  51.     for (auto v : v1) std::cout << v << ' ';
  52.     system("pause");
  53.     return 0;
  54. }
  55.  
  56. // Реализовать проверку корректности (чтобы программа не вылетала)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement