[NOIP2008] Raise the group Rokua P1125 silly Little Monkey

Source: Internet
Author: User

Title Description

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.

Input/output format

Input format:

The input file word.in only one line, which is a word, where only lowercase letters are possible and the length is less than 100.

Output format:

Output file Word.out 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.

Input and Output Sample input example # #:
[Input1]error[input2]olympic
Sample # # of output:
[OUTPUT1] Lucky Word2[output2]no Answer0
Description

"Input and output Example 1 explanation"

The letter R that appears most in the word error appears 3 times, the letter with the fewest occurrences appears 1 times, 3-1=2,2 is a prime number.

"Input and output Example 2 explanation"

The most appearing letters I appeared 2 times in the word Olympic, the letters with the fewest occurrences occurred 1 times, 2-1=1,1 were not prime numbers.

Note: The original question is interpreted incorrectly here, actually 0, not prime.

Noip2008 Raise the first question

Bucket count, simulation can be

1 /*by Silvern*/2#include <algorithm>3#include <iostream>4#include <cstring>5#include <cstdio>6#include <cmath>7#include <vector>8 using namespacestd;9 Const intmxn= -;Ten CharS[MXN]; One intLen; A BOOLPdintx) { -     if(x==1|| x==0)return 0; -     intm=sqrt (x); the      for(intI=2; i<=m;i++){ -         if(x%i==0)return 0; -     } -     return 1; + } - intcnt[ -]; + intMain () { Ascanf"%s", s+1); at     inti,j; -Len=strlen (s+1); -      for(i=1; i<=len;i++) cnt[s[i]-'a'+1]++; -     intmx=0, mi=1e9; -      for(i=1; i<= -; i++){ -         if(!cnt[i])Continue; inmx=Max (mx,cnt[i]); -Mi=min (mi,cnt[i]); to     } +     intans=mx-mi; -     if(!PD (ANS)) { theprintf"No answer\n0\n"); *         return 0; $     }Panax Notoginsengprintf"Lucky word\n"); -printf"%d\n", ans); the     return 0; +}

[NOIP2008] Raise the group Rokua P1125 silly Little Monkey

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.