Nyoj 62-Dumb bear (in the corresponding array of ASC bits + 1)

Source: Internet
Author: User

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&LT;=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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.