信息學(xué)奧賽一本通——1407:笨小猴
#include <iostream>
#include <cmath>
using namespace std;
int main() { // 蒟蒻解法?
string a;
cin >> a;
// 此題我采用桶排序做?
int s[30] = {}; // 遍歷a?
for(int i=0;i<int(a.length());i++){
s[a[i] - 97] ++;
}
int maxn = 0, minn = 100;
for(int i=0;i<25;i++){ // 遍歷s,找到最大次數(shù)與最小次數(shù)?
if(s[i] > maxn){
maxn = s[i];
}
if(s[i] < minn && s[i] != 0){
minn = s[i];
}
}
bool t = 1;
for(int i=2;i * i <= (maxn - minn);i++){ // 判斷是否為質(zhì)數(shù)?
if((maxn - minn) % i == 0){
t = 0;
break;
}
}
if((maxn - minn) <= 1){ //特判0,1?
t = 0;
}
if(t){
cout << "Lucky Word" << endl << maxn - minn;
}
else{
cout << "No Answer" << endl << 0;
}
return 0;
}

希望大家一鍵三連,謝謝!
標(biāo)簽: