diff options
Diffstat (limited to 'Sources')
-rw-r--r-- | Sources/GraphAlgo.cpp | 47 |
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; +//} |