洛谷P1125[NOIP2008 提高组]
刚开始学,想不明白哪里错了,求解答
//P1125
#include<iostream>
#include<cstring>
using namespace std;
char a[200];
int b = strlen(a);
int sum[26] = {};
int isPrime(int n) {//判断素数
int isP =1;
for (int i = 2; i < n; i++) {
if (n % i == 0) {
isP = 0;
break;
}
//else
// isP = 1;
}
if (n == 1||n==0)
isP = 0;
return isP;
}
int maxn(const char a[200]) {//判断出现次数最多的字母
int max=0;
for (int i = 0; i < b; i++) {
sum[a[i] - 'a']++;
}
for (int i = 0; i < 26; i++) {
if (sum[i] > max)
max = sum[i];
}
return max;
}
int minn(const char a[200]) {//判断出现次数最少的字母
int min=110;
for (int i = 0; i < b; i++) {
sum[a[i] - 'a']++;
}
for (int i = 0; i < 26; i++) {
if (sum[i] < min&&sum[i]>0)
min = sum[i];
}
return min;
}
int main() {
cin >> a;
int b = maxn(a) - minn(a);
//cout << b;
if (isPrime(b) == 1)
cout << "Lucky Word" << endl << b;
else if (isPrime(b) == 0)
cout << "No Answer" << endl << "0";
return 0;
}