From e4f8e9ad39a6fffd84b87c4c88e98c11abfc1e2c Mon Sep 17 00:00:00 2001 From: Haidong Ji Date: Tue, 7 Aug 2018 20:13:53 -0500 Subject: Max Pairwise Product implemented! --- PlaygroundCpp/Sources/Playground.cpp | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) (limited to 'PlaygroundCpp') diff --git a/PlaygroundCpp/Sources/Playground.cpp b/PlaygroundCpp/Sources/Playground.cpp index 37b59f9..73738d3 100644 --- a/PlaygroundCpp/Sources/Playground.cpp +++ b/PlaygroundCpp/Sources/Playground.cpp @@ -1,13 +1,27 @@ #include +using std::cin; +using std::cout; -int add(int a, int b) { - return a + b; -} int main() { - int a = 0; - int b = 0; - std::cin >> a; - std::cin >> b; - std::cout << add(a, b); + int bigger = 0; + int biggest = 0; + int n; + int i; + cin >> n; + + for (int j = 0; j < n; j++) { + cin >> i; + if (i > biggest) { + bigger = biggest; + biggest = i; + } else if (i == biggest) { + bigger = i; + } else if (i > bigger) { + bigger = i; + } + } + + int64_t prod = (int64_t) bigger * (int64_t) biggest; + cout << prod << "\n"; return 0; } -- cgit v1.2.3