fork download
  1. #include <numeric>
  2. #include <vector>
  3. #include <iostream>
  4.  
  5. struct Path
  6. {
  7. std::vector<double> distance;
  8. std::vector<double> safety;
  9. };
  10.  
  11. int main()
  12. {
  13. std::vector<Path> paths{
  14. {
  15. { 1.0, 2.0 }, {}
  16. },
  17. {
  18. { 3.0 }, {}
  19. }
  20. };
  21.  
  22. double sum = 0.0;
  23. for ( auto const& path : paths ) {
  24. for ( double d : path.distance ) {
  25. sum += d;
  26. }
  27. }
  28. std::cout << sum << std::endl;
  29.  
  30. std::cout <<
  31. std::accumulate(
  32. paths.begin(),
  33. paths.end(),
  34. 0,
  35. [](double res, Path const& path) {
  36. return res + std::accumulate(path.distance.begin(), path.distance.end(), 0);
  37. })<<std::endl;
  38.  
  39. }
Success #stdin #stdout 0s 3476KB
stdin
Standard input is empty
stdout
6
6