Advertisement
Infiniti_Inter

Volod9

Dec 13th, 2018
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.54 KB | None | 0 0
  1. #include <iostream>
  2. #include<string>
  3. #include<stdio.h>
  4. #include <algorithm>
  5.  
  6. using namespace std;
  7.  
  8. int a[1000];
  9.  
  10. const int INF = 1e9;
  11. int main()
  12. {
  13.     int n;
  14.     cin >> n;
  15.     int k;
  16.     cin >> k;//какой элемент вставлять
  17.     int Max = -INF;
  18.     for (int i = 0; i < n; ++i)
  19.     {
  20.         cin >> a[i];
  21.         Max = max(Max, a[i]);
  22.     }
  23.     for (int i = 0; i < n; ++i)
  24.         if (a[i] == Max)
  25.         {
  26.             for (int j = n; j > i; j--)
  27.                 a[j] = a[j - 1];
  28.             a[i + 1] = k;
  29.             i++;
  30.             n++;
  31.         }
  32.     for (int i = 0; i < n; ++i)
  33.         cout << a[i] << ' ';
  34.    
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement