fork(2) download
  1. #include <iostream>
  2. #include <algorithm>
  3. using namespace std;
  4.  
  5. template< typename T >
  6. bool negative( T x )
  7. {
  8. return x < 0 ;
  9. }
  10.  
  11. int main() {
  12. int size;
  13. cin >> size;
  14. vector<double> array( size );
  15. generate( begin( array ),
  16. end ( array ),
  17. []()
  18. {
  19. int x;
  20. cin >> x;
  21. return x;
  22. } );
  23. double product = 1.0;
  24. for_each( begin( array ),
  25. end ( array ),
  26. [&product]( auto x )
  27. {
  28. if( negative( x ) )
  29. {
  30. product *= x;
  31. }
  32. } );
  33. cout << product << " " << count_if( begin( array ),
  34. end ( array ),
  35. negative<double>
  36. );
  37. return 0;
  38. }
Success #stdin #stdout 0s 3232KB
stdin
5
3
-3
2
-2
-5
stdout
-30 3