题解 | #[NOIP2008]笨小猴#
[NOIP2008]笨小猴
http://www.nowcoder.com/practice/17865bc2a75c4944a872ef709958c56e
#include<string.h>
int output(int a) { //判断是否为质素
int count = 0;
for (int i = 1; i <= a; i++) {
if (a % i == 0) count++;
}
if (count == 2) return a; //是,返回传入值a
else return 0; //否,返回0
}
int main() {
int maxn = 0, minn = 100, count = 0, sizen;
char s[100];
scanf("%s", &s);
sizen = strlen(s);
for (int i = 0; i < sizen; i++) { //记录每个相同单词的个数
for (int j = 0; j < sizen; j++) {
if (s[i] == s[j]) count++;
}
if (count > maxn) maxn = count; //记录最大个数
if (count < minn) minn = count; //记录最小个数
count = 0;
}
int val = output(maxn - minn);
if (val != 0) printf("Lucky Word\n%d", val); //返回值不为0时,结果为质素
else printf("No Answer\n0"); //否则结果不为质素
return 0;
}