Advertisement
myloyo

вектор лист normal

May 18th, 2023 (edited)
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.00 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <vector>
  4. #include <algorithm>
  5. #include <list>
  6. #include <fstream>
  7.  
  8. using namespace std;
  9. ifstream in("input.txt");
  10. ofstream out("output.txt");
  11.  
  12. int main() {
  13.     int value;
  14.     int n;
  15.     cin >> n;
  16.     vector<int> a;
  17.     list<int> b;
  18.     for (int i = 0; i < n; i++)
  19.     {
  20.         cin >> value;
  21.         a.push_back(value);
  22.         b.push_back(value);
  23.     }
  24.  
  25.     int x, y;
  26.     cin >> x >> y;
  27.     list<int>::iterator iter;
  28.     iter = b.begin();
  29.     for (int i = 1; i < b.size() / 2 + 1; i++) {
  30.         iter++;
  31.     }
  32.     b.insert(iter, x);
  33.     iter++;
  34.     b.insert(iter, y);
  35.  
  36.     for (iter = b.begin(); iter != b.end(); iter++) {
  37.         cout << *iter << " ";
  38.     }
  39.     cout << endl;
  40.     a[0] = a[0] - 1;
  41.     a[1] = a[1] - 1;
  42.     a[a.size() - 1] = a[a.size() - 1] - 1;
  43.     a[a.size() - 2] = a[a.size() - 2] - 1;
  44.  
  45.     for (auto it = a.begin(); it != a.end(); it++) {
  46.         cout << *it << " ";
  47.     }
  48.  
  49.     return 0;
  50. }
  51. 5
  52. 1 2 3 4 5
  53. 6 8
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement