aboutsummaryrefslogtreecommitdiff
path: root/challenge-088/hstejas/cpp
diff options
context:
space:
mode:
authorhstejas <tejashs@rocketmail.com>2020-11-29 22:27:52 +0530
committerhstejas <tejashs@rocketmail.com>2020-11-29 22:30:09 +0530
commitb86ae93a0073163f62b59d076faca0a108dd430d (patch)
tree2c8f2db21a3e607cf9a4ca28dd8995c1874ce0e2 /challenge-088/hstejas/cpp
parente5f5309fd45b7e190c3bf574304d3b9b42ce185a (diff)
downloadperlweeklychallenge-club-b86ae93a0073163f62b59d076faca0a108dd430d.tar.gz
perlweeklychallenge-club-b86ae93a0073163f62b59d076faca0a108dd430d.tar.bz2
perlweeklychallenge-club-b86ae93a0073163f62b59d076faca0a108dd430d.zip
Challenge 88
Diffstat (limited to 'challenge-088/hstejas/cpp')
-rw-r--r--challenge-088/hstejas/cpp/ch1.cpp35
1 files changed, 35 insertions, 0 deletions
diff --git a/challenge-088/hstejas/cpp/ch1.cpp b/challenge-088/hstejas/cpp/ch1.cpp
new file mode 100644
index 0000000000..a12760aac0
--- /dev/null
+++ b/challenge-088/hstejas/cpp/ch1.cpp
@@ -0,0 +1,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;
+} \ No newline at end of file