tips:
由于数据量很小,不用打印素数表,直接判断就行!!
code:
#include <iostream>
#include <string>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;
bool isPrime(int n)
{
if(n<2)
return false;
else for(int i=2;i<=sqrt(n+0.5);i++)
{
if(n%2==0)
return false;
}
return true;
}
int main()
{
int t;
char s[110];
int vis[26];
int mins,maxs;
cin>>t;
while(t--){
memset(vis,0,sizeof(vis));
cin>>s;
for(int i=0;s[i];i++){
vis[s[i]-'a']++;
}
sort(vis,vis+26);
for(int i=0;i<26;i++)
{
if(vis[i]){
mins=vis[i];
break;
}
}
maxs=vis[25];
if(isPrime(maxs-mins)){
cout<<"Lucky Word"<<endl<<maxs-mins<<endl;
}
else
cout<<"No Answer"<<endl<<"0"<<endl;;
}
return 0;
}