# Uchiha_Itachi 的博客

### 题解 P1125 【笨小猴】

posted on 2018-08-12 17:40:01 | under 题解 |

#include <bits/stdc++.h>
using namespace std;

int cti(char ch)
{
return (int)ch - 96;
}//map from char to int

bool isprime(int n)
{
int temp = ceil(sqrt(n));
if(n == 2)
return true;
if(n == 1 || n == 0)
return false;
for(int i = 2;i <= temp;i++)
{
if(n % i == 0)
return false;
}
return true;
} //prime judge

int appear[27];//each letter's appear time
char word[101];//word

int main()
{
cin >> word;
int sz = strlen(word);
for(int i = 0;i < sz;i++)
{
appear[cti(word[i])]++;//process each letter
}
for(int i = 1;i <= 26;i++)
{
cout << char(i + 64) << ": " << appear[i] << endl;
}
sort(appear + 1,appear + 26);
int minn = 0;
for(int i = 1;i <= 26;i++)
{
if(appear[i])
{
minn = appear[i];//the first non-0 number is the smallest
break;
}
}
int maxn = -1;
for(int i = 1;i <= 26;i++)
{
maxn = max(maxn,appear[i]);
}
cout << "Max: " << maxn << endl << "Min: " << minn << endl;
if(isprime(maxn - minn))//prime
{
cout << "Lucky Word" << endl;
cout << maxn - minn << endl;//as problem
}
else
{
cout << "No Answer" << endl;
cout << 0 << endl;//as problem
}
return 0;
}