diff options
author | Haidong Ji | 2018-08-07 20:13:53 -0500 |
---|---|---|
committer | Haidong Ji | 2018-08-07 20:13:53 -0500 |
commit | e4f8e9ad39a6fffd84b87c4c88e98c11abfc1e2c (patch) | |
tree | 60688b5790e0b30abf4a10c4a4ca7ede8ee133be | |
parent | 2d9b3e3e4cd41dc80e4759b07fd18b89477be2cb (diff) |
Max Pairwise Product implemented!
-rw-r--r-- | PlaygroundCpp/Sources/Playground.cpp | 30 |
1 files changed, 22 insertions, 8 deletions
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 <iostream> +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; } |