笨小熊

#include<iostream>
#include<string>
#include<math.h>
#define MAX_NUM 100
using namespace std;

bool app(int n)
{
    int i;
    if(n>=2)
    {
        for(i=2;i<=sqrt(double(n));i++)
        {
            if(n%i==0)
                return 0;
        }
        return 1;
    }
    else
        return 0;
}


int main()
{
    string str;
    int i,j,n,a[MAX_NUM],count[MAX_NUM],flag[MAX_NUM],max,min,tmp;
    cin>>n;
    while(n--)
    {
        cin>>str;
        for(i=0;i<str.size();i++)
        {
            count[i]=0;
            flag[i]=0;
        }
        for(i=0;i<str.size();i++)
            for(j=i;j<str.size();j++)
                {
                    if(flag[j]==0&&str[i]==str[j])
                    {
                        count[i]++;
                        flag[j]=1;
                    }
                }
        max=count[0];
        for(i=1;i<str.size();i++)
        {
            if(count[i]>max)
                max=count[i];
        }
        min=max;
        for(i=0;i<str.size();i++)
        {
            if(count[i]<min&&count[i]!=0)
                min=count[i];
        }
        if(app(max-min))
        {
            cout<<"Lucky Word"<<endl;
            cout<<max-min<<endl;
        }
        else
        {
            cout<<"No Answer"<<endl;
            cout<<"0"<<endl;
        }
    }
    return 0;
    
}

 

posted @ 2012-09-19 23:30  Afraid  阅读(162)  评论(0)    收藏  举报