Advertisement
ilnazEPTA

Untitled

Dec 22nd, 2019
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.70 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3. int main()
  4. {
  5. int n;
  6. cout << "Enter n:";
  7. cin >> n;
  8. int* a = new int[n];
  9. for (int i = 0; i < n; i++)
  10. cin >> a[i];
  11.  
  12. int i = 0, k, g, j = n - 1;
  13. while (i < j)
  14. {
  15. if (a[i] % 2 != 0 && a[j] % 2 == 0)
  16. {
  17. swap(a[i], a[j]); i++; j--;
  18. }
  19.  
  20. if (a[i] % 2 == 0)
  21. {
  22. for (int ind = i + 1; ind < j; ind++)
  23. {
  24. if (a[ind] % 2 == 0)
  25. k = ind;
  26.  
  27. }
  28. swap(a[i], a[k]);
  29. i++;
  30. }
  31.  
  32. if (a[j] % 2 != 0)
  33. {
  34. for (int ind = j - 1; ind > i; ind--)
  35. {
  36. if (a[ind] % 2 != 0)
  37. g = ind;
  38.  
  39. }
  40. swap(a[j], a[g]);
  41. j--;
  42. }
  43.  
  44. }
  45. for (int b = 0; b < n; b++)
  46. cout << a[b];
  47.  
  48.  
  49.  
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement