aboutsummaryrefslogtreecommitdiff
path: root/challenge-088/hstejas/cpp/ch-1.cpp
blob: a12760aac07a2beb76e1cdfe459f103b384eab4f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#include<iostream>
#include<algorithm>
#include<vector>

std::ostream& operator<<(std::ostream& out, const std::vector<int>& in)
{
    if(in.empty())
        return out;

    out << in[0];
    for(size_t i = 1; i < in.size(); i++)
        out << ", " << in[i];

    return out;
}

std::vector<int> arrayOfProduct(const std::vector<int>& arr)
{
    int product = 1;
    for(const int& n : arr)
        product *= n;

    std::vector<int> ret(arr.size(), product);

    for(size_t i = 0; i < arr.size(); i++)
        ret[i] /= arr[i];

    return ret;
}

int main()
{
    std::cout << arrayOfProduct({5, 2, 1, 4, 3}) << std::endl;
    std::cout << arrayOfProduct({2, 1, 4, 3}) << std::endl;
}