SHARE
TWEET

Untitled

a guest Jun 27th, 2019 59 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include "stdafx.h"
  2. #include <iostream>
  3. #include <fstream>
  4. #include <vector>
  5.  
  6. using namespace std;
  7.  
  8. ifstream in("input.txt");
  9. ofstream out("output.txt");
  10.  
  11. int main()
  12. {
  13.     vector <int> a;
  14.     int x, y, c;
  15.     int n = 0;
  16.     in >> x >> y;
  17.  
  18.     while (in >> c)
  19.     {
  20.         a.push_back(c);
  21.         n++;
  22.     }
  23.  
  24.     if (a.size() == 0)
  25.         return 0;
  26.     else
  27.     {
  28.         if (n % 2 != 0)
  29.         {
  30.             a.insert(a.begin() + n / 2 + 1, y); // вставляем элемент "y" после среднего элемента
  31.             a.insert(a.begin() + n / 2, x); // вставляем элемент "x" перед средним элементом
  32.             n += 2;
  33.         }
  34.  
  35.         for (int i = 0; i < n; i++)
  36.             out << a[i] << ' ';
  37.         return 0;
  38.  
  39.     }
  40. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top