50分求助
查看原帖
50分求助
1041765
AKkkk_TIX楼主2024/8/7 17:40
#include <bits/stdc++.h>
using namespace std;
struct ts{
    char ch;
    int times;
    ts(){
        ch = '\0';
        times = 0;
    }
}tmp[100];
bool p(int x){
	if(x != 0){
    int k;
    for (k = 2;k <= sqrt(x) && (x % k == 0);k++);
    if (k > sqrt(x))
        return true;
    else
        return false;
	}
	else
		return false;
}
string str;
int maxn = -0x7f, minn = 0x7f, i, j;
int main(){
    cin >> str;
    for(i = 0;i < str.length();i++){
        for(j = 0;tmp[j].ch != '\0';j++)
            if(tmp[j].ch == str[i])    
                break;
        if(tmp[j].ch == '\0'){
            tmp[j].ch = str[i];
            tmp[j].times = 1;
        }
        else
            tmp[j].times++;
    }
    for(i = 0;tmp[i].ch != '\0';i++)
        if(tmp[i].times > maxn)
            maxn = tmp[i].times;
        else if(tmp[i].times < minn)
            minn = tmp[i].times;
    int ans = maxn - minn;
    if( p(ans) )
        cout << "Lucky Word\n" << ans;
    else
        cout << "No Answer\n0";
        
    return 0;
}

奇怪的码风

测评记录

2024/8/7 17:40
加载中...