fork download
  1. #include <iostream>
  2. #include <algorithm>
  3. #include <cmath>
  4. using namespace std;
  5.  
  6. int main() {
  7. int n = 0;
  8. cout << "n=";
  9. cin >> n;
  10. double* a = new double[n];
  11. cout << "Enter " << n << " elements:\n";
  12.  
  13. for (int i = 0; i < n; i++)
  14. cin >> a[i];
  15.  
  16. cout << endl;
  17. partition(a, a + n, [](double b) {
  18. return fabs(b) <= 1;
  19. });
  20.  
  21. for (int i = 0; i < n; i++)
  22. cout << a[i] << " ";
  23.  
  24. cout << endl;
  25. delete[]a;
  26. }
  27.  
Success #stdin #stdout 0s 4924KB
stdin
10
0.1 2 -3.5 -0.2 2.9 -0.5 0.5 3 9 -10
stdout
n=Enter 10 elements:

0.1 0.5 -0.5 -0.2 2.9 -3.5 2 3 9 -10