summaryrefslogtreecommitdiff
path: root/Sources
diff options
context:
space:
mode:
authorHaidong Ji2020-05-09 15:32:19 -0500
committerHaidong Ji2020-05-09 15:32:19 -0500
commitf13dfb8c438c3c565ed4ede430e6046f54e5c9d5 (patch)
tree22c056ca5fec003a2f4fc09bdf0c1faccdf0b3da /Sources
parent570b84f60a05be1f765e15207b8a437610dc8893 (diff)
Machine rebuilt so I had to reconfig Eclipse and googletest for C++ dev
work on Linux
Diffstat (limited to 'Sources')
-rw-r--r--Sources/GraphAlgo.cpp47
1 files changed, 47 insertions, 0 deletions
diff --git a/Sources/GraphAlgo.cpp b/Sources/GraphAlgo.cpp
new file mode 100644
index 0000000..d04987f
--- /dev/null
+++ b/Sources/GraphAlgo.cpp
@@ -0,0 +1,47 @@
+#include <iostream>
+#include <vector>
+#include <algorithm>
+#include <gtest/gtest.h>
+
+using std::vector;
+
+static long getMaxDotProduct(vector<int> a, vector<int> b) {
+ std::sort(a.begin(), a.end());
+ std::sort(b.begin(), b.end());
+ long result = 0;
+ for (int i = 0; i < b.size(); i++) {
+ result = (long) a[i]*b[i]+result;
+ }
+ return result;
+}
+
+TEST(MaxDotProduct, Max1) {
+ vector<int> a = { 60, 100, 120 };
+ vector<int> b = { 20, 50, 30 };
+ ASSERT_EQ(getMaxDotProduct(a, b), 10200);
+}
+
+//TEST(MaxDotProduct, Max2) {
+// vector<int> a = { 23 };
+// vector<int> b = { 39 };
+// ASSERT_EQ(getMaxDotProduct(a, b), 897);
+//}
+//
+//TEST(MaxDotProduct, Max3) {
+// vector<int> a = { 1,3,-5 };
+// vector<int> b = { -2,4,1 };
+// ASSERT_EQ(getMaxDotProduct(a, b), 23);
+//}
+
+//int main() {
+// size_t n;
+// std::cin >> n;
+// vector<int> a(n), b(n);
+// for (size_t i = 0; i < n; i++) {
+// std::cin >> a[i];
+// }
+// for (size_t i = 0; i < n; i++) {
+// std::cin >> b[i];
+// }
+// std::cout << getMaxDotProduct(a, b) << std::endl;
+//}