blob: 722df1bf47c5e2e06acfd98c77fbe0646b36e3f3 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
|
// Godbolt Link: https://godbolt.org/z/dGGKzdYhn
#include <algorithm>
#include <numeric>
#include <vector>
#include <functional>
auto array_product(std::vector<int> v) -> std::vector<int> {
auto const prod = std::accumulate(v.cbegin(), v.cend(), 1, std::multiplies{});
std::transform(v.cbegin(), v.cend(), v.begin(), [=] (auto e) { return prod / e; });
return v;
}
|