1765. 笨小猴

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;
}



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值