题解 | #[NOIP2008]笨小猴#
[NOIP2008]笨小猴
https://www.nowcoder.com/practice/17865bc2a75c4944a872ef709958c56e
#include <stdio.h> #include <string.h> int main() { char arr[100]; scanf("%s", &arr); int max, s, a; int min = 100; int count = 0; for (int i = 0; i < strlen(arr); i++) { count = 0; for (int j = i; j < strlen(arr); j++) { //判断一样的有多少个 if (arr[i] == arr[j] && arr[j - 1] != arr[i]) { count++; } } //判断大小 if (count > max) max = count; else min = count; } //最大值减最小值 s = max - min; //判断是不是素数也称质数 for (int i = 2; i < s; i++) { a = 1; if (s % i == 0) { a = 0; break; } } if (a == 1 && s != 1) printf("Lucky Word\n%d\n",s); else printf("No Answer\n0\n"); return 0; }