题解 | #[NOIP2008]笨小猴#
[NOIP2008]笨小猴
https://www.nowcoder.com/practice/17865bc2a75c4944a872ef709958c56e
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scan = new Scanner(System.in); String str = scan.next(); int maxn = 0; int minn = str.length(); for (int i = 0; i < str.length(); i++) { int temp1 = 0; for (int j = 0; j < str.length(); j++) { if (str.charAt(i) == str.charAt(j)) { temp1++; } } if (maxn < temp1) { maxn = temp1; } if (minn > temp1) { minn = temp1; } } // System.out.println(maxn + " " + minn); int z = maxn - minn; if (z <= 1) { System.out.print("No Answer\n" + 0); } else { boolean loop = true; for (int i = 2; i < z; i++) { if (z % i == 0) { loop = false; } } if (loop) { System.out.println("Lucky Word\n" + z); } } } }
Java基础练习题 文章被收录于专栏
都是一些基础的语法题目,每天可以刷几道。