From edbf5a63d912c44b6da9235f8a17550ae5057cc0 Mon Sep 17 00:00:00 2001 From: LittleSheep Date: Sun, 26 May 2024 14:58:02 +0800 Subject: [PATCH] =?UTF-8?q?:white=5Fcheck=5Fmark:=20=E4=B8=BB=E8=A6=81?= =?UTF-8?q?=E6=88=90=E5=88=86=20map=20=E5=AE=9E=E7=8E=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- take-most-space-element/main.cc | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 take-most-space-element/main.cc diff --git a/take-most-space-element/main.cc b/take-most-space-element/main.cc new file mode 100644 index 0000000..28d6164 --- /dev/null +++ b/take-most-space-element/main.cc @@ -0,0 +1,33 @@ +#include +using namespace std; + +int read() { + int x = 0, w = 1; + char ch = 0; + while (ch < '0' || ch > '9') { + if (ch == '-') + w = -1; + ch = getchar(); + } + while (ch >= '0' && ch <= '9') { + x = x * 10 + (ch - '0'); + ch = getchar(); + } + return x * w; +} + +int main() { + int n = read(); + unordered_map u; + for (int i = 0; i < n; i++) { + int val = read(); + u[val]++; + } + for (const auto &[key, value] : u) { + if (value >= n / 2) { + printf("%d\n", key); + return 0; + } + } + printf("No\n"); +}