Nanyang 62 (Dumb Bear)

Source: Internet
Author: User

Stupid Bear time limit:MS | Memory limit:65535 KB Difficulty:2
Describe

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
The
first row of data N (0<N<100) represents the number of test data groups.
Each set of test data input has only one row, which is a word, where only lowercase letters are possible and the length is less than 100.
Output
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 the value of Maxn-minn, otherwise output 0
Sample input
2 Errorolympic

Sample output
Lucky Word 2 No Answer 0

Source
NOIP2008
//small details;
1#include <stdio.h>2#include <string.h>3#include <math.h>4#include <algorithm>5 using namespacestd;6 intZhishu (inta)7 {8     inti,b=0;9      for(i=2; I<=sqrt (a); i++)Ten     { One         if(a%i==0) Ab++; -     } -     if(a==1|| a==0) the     return 0; -     Else -     { -         if(b==0) +         return 1; -         Else  +         return 0; A     } at } - intMain () - { -     intm; -scanf"%d",&m); -      while(m--) in     { -         Charstr[101]; toscanf"%s", str); +          -         intlen=strlen (str); theSort (str,str+len); *         intb=1, max=-1010, min=1010; $          for(intI=0; i<len;i++)Panax Notoginseng         { -             if(str[i]==str[i+1]) theb++; +             Else A             { the                 if(b>max) +max=b; -                 if(b<min) $min=b; $b=1; -             }  -         } the         if(Zhishu (max-min)) -         {Wuyiprintf"Lucky word\n%d\n", max-min); the         } -         Else Wuprintf"No answer\n0\n"); -     } About     return 0; $}

All practice;

Nanyang 62 (Dumb Bear)

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.