fork download
  1. #include <iostream>
  2. #include <vector>
  3. #include <numeric>
  4. #include <limits>
  5.  
  6. int main()
  7. {
  8. using dvect = std::vector<double>;
  9. using ddvect = std::vector<dvect>;
  10. using dddvect = std::vector<ddvect>;
  11. dddvect mx = { { { 1, 2, 3 }, { -1, 3 }, { 8,-2, 3 } },
  12. { {}, { -1, 25, 3 }, { 7, 3, 3 } },
  13. { { -1, -2, -3 }, {}, { 33 } } };
  14.  
  15. struct max_value {
  16. size_t i = 0;
  17. size_t j = 0;
  18. size_t k = 0;
  19.  
  20. double value = -std::numeric_limits<double>::infinity();
  21.  
  22. max_value() = default;
  23. max_value( size_t i, size_t j, size_t k, double v ) : i( i ), j( j ), k( k ), value( v ) {}
  24.  
  25. max_value operator<<( const max_value &v ) const
  26. {
  27. return value > v.value ? *this : v;
  28. }
  29.  
  30. };
  31.  
  32. size_t i = 0;
  33. auto max = std::accumulate( mx.begin(), mx.end(), max_value{}, [&mx]( const max_value &val, const ddvect &ddv ) {
  34. auto i = std::distance( &*mx.cbegin(), &ddv );
  35. return std::accumulate( ddv.begin(), ddv.end(), val, [i,&ddv]( const max_value &val, const dvect &dv ) {
  36. auto j = std::distance( &*ddv.cbegin(), &dv );
  37. return std::accumulate( dv.begin(), dv.end(), val, [i,j,&dv]( const max_value &val, const double &d ) {
  38. auto k = std::distance( &*dv.cbegin(), &d );
  39. return val << max_value( i, j, k, d );
  40. } );
  41. } );
  42. } );
  43.  
  44. std::cout << "max value " << max.value << "[" << max.i << "," << max.j << "," << max.k << "]" << std::endl;
  45. }
  46.  
Success #stdin #stdout 0s 15240KB
stdin
Standard input is empty
stdout
max value 33[2,2,0]