1 条题解

  • 0
    @ 2024-8-14 16:53:28
    #include<bits/stdc++.h>
    using namespace std;
    
    bool isPrime(int n) {
        if (n < 2) {
            return false;
        }
        for (int i = 2; i <= sqrt(n); i++) {
            if (n % i == 0) {
                return false;
            }
        }
        return true;
    }
    
    int main() {
        string word;
        cin >> word;
    
        vector<int> count(26, 0);
    
    	for (int i = 0; i < word.length(); i++) {
        	char ch = word[i];
        	int index = ch - 'a';
        	count[index]++;
    	}
    
        int maxn = 0;
        int minn = 100;
    
        for (int i = 0; i < 26; i++) {
            if (count[i] > maxn) {
                maxn = count[i];
            }
            if (count[i] < minn && count[i] != 0) {
                minn = count[i];
            }
        }
    
        if (isPrime(maxn - minn)) {
            cout << "Lucky Word" << endl;
            cout << maxn - minn << endl;
        } else {
            cout << "No Answer" << endl;
            cout << 0 << endl;
        }
    
        return 0;
    }
    

    很古早的代码 在我的文件夹里 应该不是我写的 ##仅供参考

    • 1

    【深基6.例3】[NOIP2008 提高组] 笨小猴

    信息

    ID
    129
    时间
    1000ms
    内存
    256MiB
    难度
    10
    标签
    递交数
    1
    已通过
    1
    上传者