哪错了??居然60!!!
查看原帖
哪错了??居然60!!!
1377083
fengzi_lc楼主2024/12/9 23:16
#include<iostream>
using namespace std;
#include<string>
#include<vector>
#include<math.h>
#include <algorithm>
bool isPrime(int n)
{
    if (n == 0)return false;
    for (int i = 2; i* i <= n; i++)
    {
        if (n % i == 0)
        {
            return false;
        }
    }
    return true;
}
int main()
{

    string s;
    cin >> s;
    int dif = 0;
    int hash[26] = { 0 };
    for (int i = 0; i < s.size(); i++)
    {
        hash[s[i] -'a']++;
    }
    int maxx = -100, minn = 100;
    for (int i = 0; i < 26; i++)
    {
        if (maxx < hash[i])
        {
            maxx = hash[i];
        }
         if (minn > hash[i] && hash[i] != 0)
        {
            minn = hash[i];
        }
    }
    dif = maxx - minn;

    if (isPrime(dif))
    {
        cout << "Lucky Word" << endl;
        cout << dif;
    }
    else
    {
        cout << "No Answer" << endl;
        cout<<0;
    }
    
    return 0;
}
2024/12/9 23:16
加载中...