From 1d8ca13bfae6dea78c3bc4de413532d7542a927f Mon Sep 17 00:00:00 2001 From: Ren Baoshuo Date: Tue, 30 Nov 2021 20:08:43 +0800 Subject: [PATCH] =?UTF-8?q?P1125=20[NOIP2008=20=E6=8F=90=E9=AB=98=E7=BB=84?= =?UTF-8?q?]=20=E7=AC=A8=E5=B0=8F=E7=8C=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit R63986007 --- Luogu/P1125/P1125.cpp | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 Luogu/P1125/P1125.cpp diff --git a/Luogu/P1125/P1125.cpp b/Luogu/P1125/P1125.cpp new file mode 100644 index 00000000..c192c5aa --- /dev/null +++ b/Luogu/P1125/P1125.cpp @@ -0,0 +1,38 @@ +#include + +using std::cin; +using std::cout; +using std::endl; + +int max, min; +std::string s; +std::map map; + +bool isPrime(int x) { + if (x < 2) return false; + for (int i = 2; i * i <= x; i++) { + if (x % i == 0) return false; + } + return true; +} + +int main() { + max = std::numeric_limits::min(); + min = std::numeric_limits::max(); + cin >> s; + for (char c : s) { + map[c]++; + } + for (auto c : map) { + max = std::max(max, c.second); + min = std::min(min, c.second); + } + if (isPrime(max - min)) { + cout << "Lucky Word" << endl + << max - min << endl; + } else { + cout << "No Answer" << endl + << 0 << endl; + } + return 0; +}