Question ID: 1015
Title: Stupid monkey
Effective time consumption: 390 MS
Space consumption: 1832 KB
Program code:
1 import java.io.BufferedReader; 2 import java.io.IOException; 3 import java.io.InputStreamReader; 4 import java.util.Scanner; 5 6 public class Main { 7 static int m; 8 static boolean isPrime(int a){ 9 if(a<2)10 return false;11 if(a==2)12 return true;13 for(int i=2;i*i<a;i++){14 if(a%i==0)15 return false;16 }17 return true; 18 }19 20 static boolean isan(String s){21 int x=‘z‘-‘a‘+1;22 int[] a=new int[x];23 for(int i=0;i<x;i++){24 a[i]=0;25 }26 if(s.length()==0)27 return false;28 for(int i=0;i<s.length();i++){29 a[s.charAt(i)-‘a‘]++;30 }31 32 int maxm=0,minm=10000;33 for(int i=0;i<x;i++){34 if(a[i]>maxm)35 maxm=a[i];36 if(a[i]!=0&&a[i]<minm)37 minm=a[i];38 }39 m=maxm-minm;40 return isPrime(maxm-minm); 41 }42 43 44 45 /**46 * @param args47 */48 public static void main(String[] args) {49 // TODO Auto-generated method stub50 Main main=new Main();51 Scanner sc=new Scanner(System.in);52 String s;53 s=sc.next();54 if(isan(s)){55 System.out.println("Lucky Word");56 System.out.println(m);57 }else {58 System.out.println("No Answer");59 System.out.println(0);60 }61 62 } 63 64 }
Description
Stupid monkeys have a small vocabulary, so they have a headache every time they make English choices. However, he found a method. The experiment proves that it is very likely to select the right option when using this method!
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, and Minn is the number of occurrences of the letters with the least number of occurrences in a word, if maxn-Minn is a prime number, the stupid monkey thinks it is a lucky word. Such words are probably the correct answer.
The input format is only one line, which is a word. Only lowercase letters may appear, and the length is less than 100. The output format consists of two rows. The first row is a string. If the input word is lucky word, the output is "Lucky word". Otherwise, the output is "no answer ";
The second line is an integer. If the input word is lucky word, the value of maxn-Minn is output; otherwise, 0 is output. Sample Input
Example 1: Error Example 2: Olympus
Sample output
Example 1: Lucky word2 Example 2: No answer0
Data range and prompt [Example 1 of input and output] The r letter with the most error occurs three times, and the r letter with the least number of occurrences appears one time, 3-1 = 2, 2 is the prime number. [Example 2 of input and output] The most frequently occurring letter I appears twice in the word Olympus IC, the least frequently occurring letter appears once, and 2-1 = is not a prime number.
P1015 stupid monkey-smart online judge