救!为啥不能ac嘞
查看原帖
救!为啥不能ac嘞
663326
czm2526366楼主2022/2/10 23:49
using namespace std;
#include<iostream>
#include<algorithm>
#include<math.h>
#include<iomanip>


bool is_prime(int n) { 
	int stop = sqrt(n) + 1;
	if (n == 2) {
		return 1;
	}
	if (n % 2 == 0) {
		return 0;
	}
	for (int i = 3; i <= stop; i += 2) {
		if (n % i == 0) {
			return 0;
		}
	}
	return 1;
}


int main()
{
	string str;
	cin >> str;
	int a[26]{ 0 };
	for (int i = 0; i < str.size(); i++) {
		a[str[i] - 97]++;
	}
	int max=0,min=1001;
	for (int i = 0; i < 26; i++) {
		max = a[i]!=0&&a[i] > max ? a[i] : max;
		min = a[i]!=0&&a[i] < min ? a[i] : min;
	}
	if (is_prime(max - min)) {
		cout << "Lucky Word" << endl << max - min;
	}
	else {
		cout << "No Answer" << endl << 0;
	}
}
2022/2/10 23:49
加载中...