From f13dfb8c438c3c565ed4ede430e6046f54e5c9d5 Mon Sep 17 00:00:00 2001
From: Haidong Ji
Date: Sat, 9 May 2020 15:32:19 -0500
Subject: Machine rebuilt so I had to reconfig Eclipse and googletest for C++
dev work on Linux
---
.cproject | 12 +++++++++
.gitignore | 1 +
.settings/org.eclipse.cdt.core.prefs | 6 +++++
Sources/GraphAlgo.cpp | 47 ++++++++++++++++++++++++++++++++++++
4 files changed, 66 insertions(+)
create mode 100644 .gitignore
create mode 100644 .settings/org.eclipse.cdt.core.prefs
create mode 100644 Sources/GraphAlgo.cpp
diff --git a/.cproject b/.cproject
index 373a354..cde89d2 100644
--- a/.cproject
+++ b/.cproject
@@ -23,6 +23,9 @@
+
@@ -32,6 +35,13 @@
+
+
@@ -120,4 +130,6 @@
+
+
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..3df573f
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1 @@
+/Debug/
diff --git a/.settings/org.eclipse.cdt.core.prefs b/.settings/org.eclipse.cdt.core.prefs
new file mode 100644
index 0000000..c8ec5df
--- /dev/null
+++ b/.settings/org.eclipse.cdt.core.prefs
@@ -0,0 +1,6 @@
+doxygen/doxygen_new_line_after_brief=true
+doxygen/doxygen_use_brief_tag=false
+doxygen/doxygen_use_javadoc_tags=true
+doxygen/doxygen_use_pre_tag=false
+doxygen/doxygen_use_structural_commands=false
+eclipse.preferences.version=1
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
+#include
+#include
+#include
+
+using std::vector;
+
+static long getMaxDotProduct(vector a, vector 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 a = { 60, 100, 120 };
+ vector b = { 20, 50, 30 };
+ ASSERT_EQ(getMaxDotProduct(a, b), 10200);
+}
+
+//TEST(MaxDotProduct, Max2) {
+// vector a = { 23 };
+// vector b = { 39 };
+// ASSERT_EQ(getMaxDotProduct(a, b), 897);
+//}
+//
+//TEST(MaxDotProduct, Max3) {
+// vector a = { 1,3,-5 };
+// vector b = { -2,4,1 };
+// ASSERT_EQ(getMaxDotProduct(a, b), 23);
+//}
+
+//int main() {
+// size_t n;
+// std::cin >> n;
+// vector 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;
+//}
--
cgit v1.2.3