0分求助!
查看原帖
0分求助!
1051943
Curry_mvp楼主2024/8/16 08:16

基础思路:读入字符串,桶排思想,记录每一个字母出现的次数,再输出

测试点:0分全部RE

代码:

#include <bits/stdc++.h>
using namespace std;
#define int long long
int a[30];//记录26个字母的出现顺序 
string str;//处理出入的字符串 
int maxn=-1;//如题 
int minn=101;//
bool zx(int x)
{
	if(x==1)
	{
		return false;
	}
	if(x==2)
	{
		return false;
	}
	if(x==0)
	{
		return false;
	}
	for(int i=2;i*i<=x;i++)
	{
		if(x%i==0)
		{
			return true;
		}
	}
	return false;
}
signed main ()
{
	cin>>str;
	for(int i=0;i<=str.length();i++)
	{
		a[str[i]-'a'+1]++;//桶排 
	}
	for(int i=1;i<=26;i++)
	{
		maxn=max(maxn,a[i]);
		minn=min(minn,a[i]);
	}
	if(zx(maxn-minn)==true)
	{
		cout<<"Lucky Word"<<"\n";
		cout<<maxn-minn<<"\n";
	}
	else
	{
		cout<<"No Answer"<<"\n";
		cout<<"0"<<"\n";

	}
	return 0;
}

求调!

2024/8/16 08:16
加载中...