Seal_of_approval

Mass

Dec 18th, 2014
182
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.51 KB | None | 0 0
  1. #include <iostream>
  2. #include <algorithm>
  3. using namespace std;
  4. int main(void)
  5. {
  6. int n;
  7. cin >> n;
  8. int k;
  9. cin >> k;
  10. int *a = new int [n];
  11. for (int i=0; i<n; i++)
  12. cin >> a[i];
  13. int max_el=a[0];
  14. for (int i=0; i<n; i++)
  15. max_el=max(max_el,a[i]);
  16. int *b=new int [2*n];
  17. int pos=0;
  18. for (int i=0; i<n; i++)
  19. {
  20. b[pos]=a[i];
  21. pos ++;
  22. if (a[i]==max_el)
  23. {
  24. b[pos]=k;
  25. pos ++;
  26. }
  27. }
  28. for (int i=0; i<pod; i++)
  29. cout << b[i] << " ";
  30. }
Advertisement
Add Comment
Please, Sign In to add comment