#include<bits/stdc++.h>
using namespace std;
int main()
{
string a;
cin>>a; //输入单词
int word[26],maxn = 0,minn = 101; //word用来存字母的出现次数,maxn用来存最大值,minn用来存最小值
int prime[25]={2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97}; //因为单词的长度最大就100,所以我把100以内所有的质数列举了出来
for(int i = 0;i<a.length();i++) //开始判断字母个数,循环a.length()次
{
if(a[i] == 'a') //如果a[i] = 'a',word[0]+1
{
word[0]+=1;
}
else if(a[i] == 'b') //如果a[i] = 'b',word[1]+1
{
word[1]+=1;
}
else if(a[i] == 'c') //如果a[i] = 'c',word[2]+1
{
word[2]+=1;
}
else if(a[i] == 'd') //如果a[i] = 'd',word[3]+1
{
word[3]+=1;
}
else if(a[i] == 'e') //如果a[i] = 'e',word[4]+1
{
word[4]+=1;
}
else if(a[i] == 'f') //如果a[i] = 'f',word[5]+1
{
word[5]+=1;
}
else if(a[i] == 'g') //如果a[i] = 'g',word[6]+1
{
word[6]+=1;
}
else if(a[i] == 'h') //如果a[i] = 'h',word[7]+1
{
word[7]+=1;
}
else if(a[i] == 'i') //如果a[i] = 'i',word[8]+1
{
word[8]+=1;
}else if(a[i] == 'j') //如果a[i] = 'j',word[9]+1
{
word[9]+=1;
}
else if(a[i] == 'k') //如果a[i] = 'k',word[10]+1
{
word[10]+=1;
}
else if(a[i] == 'l') //如果a[i] = 'l',word[11]+1
{
word[11]+=1;
}
else if(a[i] == 'm') //如果a[i] = m'',word[12]+1
{
word[12]+=1;
}
else if(a[i] == 'n') //如果a[i] = 'n',word[13]+1
{
word[13]+=1;
}
else if(a[i] == 'o') //如果a[i] = 'o',word[14]+1
{
word[14]+=1;
}
else if(a[i] == 'p') //如果a[i] = 'p',word[15]+1
{
word[15]+=1;
}
else if(a[i] == 'q') //如果a[i] = q'',word[16]+1
{
word[16]+=1;
}
else if(a[i] == 'r') //如果a[i] = 'r',word[17]+1
{
word[17]+=1;
}
else if(a[i] == 's') //如果a[i] = 's',word[18]+1
{
word[18]+=1;
}
else if(a[i] == 't') //如果a[i] = 't',word[19]+1
{
word[19]+=1;
}
else if(a[i] == 'u') //如果a[i] = 'u',word[20]+1
{
word[20]+=1;
}
else if(a[i] == 'v') //如果a[i] = 'v',word[21]+1
{
word[21]+=1;
}
else if(a[i] == 'w') //如果a[i] = 'w',word[22]+1
{
word[22]+=1;
}
else if(a[i] == 'x') //如果a[i] = 'x',word[23]+1
{
word[23]+=1;
}
else if(a[i] == 'y') //如果a[i] = 'y',word[24]+1
{
word[24]+=1;
}
else if(a[i] == 'z') //如果a[i] = 'z',word[25]+1
{
word[25]+=1;
}
}
for(int i = 0;i<a.length();i++)
{
if(a[i]>maxn) //判断最大值
{
maxn = a[i];
}
}
for(int i = 0;i<a.length();i++)
{
if(a[i]<minn) //判断最小值
{
minn = a[i];
}
}
int zhishu = maxn-minn,z = 0; //zhishu用来存maxn-minn的值
for(int i = 0;i<25;i++)
{
if(maxn-minn == *prime) //判断是不是质数,如果是z+1
{
z++;
}
}
if(z == 1) //如果z = 1,为Lucky Word
{
cout<<"Lucky Word"<<endl;
cout<<zhishu<<endl;
}
else //否则不是
{
cout<<"No Answer"<<endl;
cout<<"0"<<endl;
}
return 0;
}
样例过了5个
各位dalao帮我看看哪里错了,thanks