62-The Dumb Little Bear
Memory limit: 64MB time limit: 2000ms special Judge:no
accepted:15 submit:43
Title Description:
Stupid Bear's vocabulary is very small, so every time to do English choice problems are very headache. But he found a way to test that the odds of choosing the right one in this way are great!
The specific description of this method is as follows: Suppose MAXN is the number of occurrences of the most frequently occurring letters in a word, Minn is the number of occurrences of the letter with the fewest occurrences of the word, and if Maxn-minn is a prime, then the dumb bear thinks it's a lucky Word, Such words are likely to be the correct answer.
Input Description:
Output Description:
Each set of test data output a total of two lines, the first line is a string, assuming the input word is Lucky Word, then output "Lucky word", otherwise output "No Answer"; The second line is an integer, if the input word is Lucky Word, Output Maxn-minn value, otherwise output 0
Sample input:Copy
2errorolympic
Sample output:
Lucky word2no Answer0
Analysis:
1. Insert the letter into the corresponding ASC code to accumulate
2, count the maximum number and the minimum number
3. Judge whether it is a prime number
C + + code implementation (AC):
1#include <iostream>2#include <algorithm>3#include <string>4#include <cmath>5 6 using namespacestd;7 8 BOOLIsPrime (intN) {9 for(intI=2; I<=SQRT (n); ++i) {Ten if(n%i = =0)return false; One } A if(n<=1)return false; - return true; - } the - intMain () { - intN; -CIN >>N; + while(N--) { - strings; + intmaxn=0, minn=0, a[ the]={0}; ACIN >>s; at - for(intI=0; I<s.length (); ++i) { -a[int(S[i]) ++; - } - -Sort (A + -, A +129, less<int>()); inMAXN = a[ -]; - to for(intI= -; ; --i) { + if(a[i-1] ==0) { -Minn =A[i]; the Break; * } $ }Panax Notoginseng - if(IsPrime (Maxn-minn)) cout <<"Lucky Word"<<endl <<maxn-minn <<Endl; the Elsecout <<"No Answer"<<endl <<"0"<<Endl; + } A return 0; the}
Nyoj 62-Dumb bear (in the corresponding array of ASC bits + 1)