1765. 笨小猴
Description
笨小猴的词汇量很小,所以每次做英语选择题的时候都很头疼。但是他找到了一种方法,经试验证明,用这种方法去选择选项的时候选对的几率非常大!
这种方法的具体描述如下:假设maxn是单词中出现次数最多的字母的出现次数,minn是单词中出现次数最少的字母的出现次数,如果maxn-minn是一个质数,那么笨小猴就认为这是个Lucky Word,这样的单词很可能就是正确的答案。
Input
输入有多组Case,每组Case只有一行,是一个单词,其中只可能出现小写字母,并且长度小于100。
Output
每组Case输出共两行,第一行是一个字符串,假设输入的的单词是Lucky Word,那么输出“Lucky Word”,否则输出“No Answer”;
第二行是一个整数,如果输入单词是Lucky Word,输出maxn-minn的值,否则输出0。
Sample Input
error
Sample Output
Lucky Word
2
// source code of submission 953254, Zhongshan University Online Judge System
#include <iostream>
#include <cmath>
#include <cstring>
using namespace std;
bool find(int x)
{
for (int i = 2 ; i < (int) sqrt(x) + 1 ; ++i)
if (x % i == 0) return false;
return true;
}
int main()
{
string s;
while (cin >> s)
{
int n = s.length();
int t = 0;;
int max = 0;
int min = 99999;
for (char c = 'a' ; c <= 'z' ; ++c)
{
t = 0;
for (int i = 0 ; i < n ; ++i)
if (s[i] == c) ++t;
if (t > max && t != 0) max = t;
if (t < min && t != 0) min = t;
}
t = max - min;
if (t == 0 || t == 1)
{
cout << "No Answer" << endl ;
cout << "0" << endl;
}
else if (find(t) || t == 2)
{
cout << "Lucky Word" << endl;
cout << t << endl;
}
else
{
cout << "No Answer" << endl;
cout << "0" << endl;
}
}
return 0;
}