题解 | #[NOIP2008]笨小猴#
[NOIP2008]笨小猴
http://www.nowcoder.com/practice/17865bc2a75c4944a872ef709958c56e
#include<iostream>
#include<string.h>
#include<stdlib.h>
using namespace std;
int main()
{
string word;
int max=0,min=100,len=0;
int num[26]={};
bool check=false;
getline(cin,word);
len=word.size();
for(int i=0;i<len;i++)
{
if(word[i]>='a' && word[i]<='z')
{
num[word[i]-'a']++;
}
if(word[i]>='A'&&word[i]<='Z')
{
num[word[i]-'A']++;
}
}
for(int i=0;i<26;i++)
{
if(num[i]>max)
{
max=num[i];
}
if(num[i]!=0&&num[i]<min)
{
min=num[i];
}
}
if(max-min!=0)
{
for(int i=2;i<max-min;i++)
{
if((max-min)%i==0)
{
break;
}
else
{
check=true;
}
}
if(check ||max-min==2)
{
cout<<"Lucky Word"<<endl;
cout<<max-min;
}
else
{
cout<<"No Answer"<<endl;
cout<<0;
}
}
else
{
cout<<"No Answer"<<endl;
cout<<0;
}
return 0;
}