NOIP200805 Monkey (Inefficient algorithm) (a big bucket of water) "A006"

Source: Internet
Author: User

"A006" stupid monkey "difficulty a" ——————————————————————————————————————————————————————————————

"Topic Requirements"

Stupid little Monkey'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! This method is described 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 stupid monkey thinks it's a lucky Word, Such words are likely to be the correct answer. (PS: Little Monkey is stupid)

"Input Requirements"

Only one line is a word, where only lowercase letters are possible, and the length is less than 100.

"Input Sample"

"Input Example 1" error "Input sample 2" Olympic

"Output Requirements"

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 the value of Maxn-minn, otherwise output 0.

"Output Sample"

"Output Example 1" Lucky Word2 "Output Sample 2" No Answer0

"Other Requirements"

"Input and Output Sample 1 explanation" The word error has the largest number of letters R appeared 3 times, the fewest occurrences of the letter appeared 1 times, 3-1=2,2 is prime.
"Input and Output Sample 2 explanation" The word Olympic the most occurrences of the letter I appeared 2 times, the smallest occurrence of the letter appeared 1 times, 2-1=1,1 is not a prime number.
"Test Analysis" amount, this monkey is really stupid, want such a crooked idea. Plus the topic of various restrictions is very loose, so I used a very stupid method-26 letters sequentially recorded occurrences, code for reference only, very low efficiency, cautious use ~!

Code

#include <iostream> #include <cstdio> #include <cmath> #include <algorithm> #include < cstring>using namespace Std;bool ISP (int n) {int t=1;if (n==1) return false;if (n==0) return false;    for (int i=2;i<=sqrt (n); i++) {        if (n%i==0) {t=0;break;}    }    if (t==1) return true;    if (t==0) return false; } int main () {    char str[100];    cin>>str;    int s;    s=97;    int len,i,j,k=0;    int maxn=0;    int minn=101;    Len=strlen (str);    for (i=0;i<26;i++)    {for        (j=0;j<len;j++)        {            if (str[j]== ' a ' +i) k++;        }        if (k==0) continue;        if (K<minn) minn=k;        if (K>MAXN) maxn=k;        k=0;    }    if (ISP (Maxn-minn) ==true)    {        cout<< "Lucky Word" <<endl;        cout<<maxn-minn;        }    else    {        cout<< "No Answer" <<endl;        cout<< "0";    }    System ("pause");    return 0;}

NOIP200805 Monkey (Inefficient algorithm) (a large bucket of water) "A006"

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.