题解 | #[NOIP2008]笨小猴#
[NOIP2008]笨小猴
https://www.nowcoder.com/practice/17865bc2a75c4944a872ef709958c56e
#include <stdio.h> int main() { char word[20]; int i = 0, sz = 0; gets(word); while (word[i]) { sz++; i++; } int j = 0,sum=0,maxn=0,minn=10; for(i=0;i<sz;i++) { sum = 0; int j; for(j=0;j<sz;j++) { if(word[i] == word[j]) { sum++; } } if(maxn<sum) { maxn = sum; } if(minn>sum) { minn = sum; } } int c = maxn-minn; int fac = 0; for (i = 2; i < c; i++) { //判断是否为素数 if (c % i == 0) { fac = 1; break; } } if (fac == 0 && c != 0 && c != 1) printf("Lucky Word\n%d", c); else printf("No Answer\n0"); return 0; }