付永康


私信TA

用户名:dotcpp0605582

访问量:824

签 名:

等  级
排  名 3372
经  验 1874
参赛次数 1
文章发表 13
年  龄 0
在职情况 学生
学  校 鄂州职业大学
专  业

  自我简介:

解题思路:

注意事项:

参考代码:

Scanner sc = new Scanner(System.in);
String str = sc.next();
int max = 0,min = str.length(),count; //注意这里要把字符串的长度赋值给min
boolean flag = true;
for (int i = 0; i < str.length(); i++) {
    max = 0;count = 0; //遍历比较完后要初始化
    for (int j = 0; j < str.length(); j++) {
        if (str.charAt(i) == str.charAt(j)) { //遍历比较,有相同的字符串count自加
            count++;
        }
    }
    if (count > max) { //如果count最大就赋值给max
        max = count;
    }
    if (count < min) { //因为min的初始值是字符串的长度,所以min最后会找出出现最少的字符
        min = count;
    }
}
//这里就是简单的求素数
for (int i = 2; i < max - min; i++) {
    flag = true;
    if (max - min % i == 0) {
        flag = false;
        break;
    }
}
if (max - min == 0 || max - min == 1) { //考虑到0和1不是素数,所以我们要直接No
    System.out.println("No Answer");
    System.out.println(0);
    return;
}
if (flag) {
    System.out.println("Lucky Word");
    System.out.println(max - min);
} else {
    System.out.println("No Answer");
    System.out.println(0);
}


 

0.0分

2 人评分

看不懂代码?想转换其他语言的代码? 或者想问其他问题? 试试问问AI编程助手,随时响应你的问题:

编程语言转换

万能编程问答  

代码解释器

代码纠错

SQL生成与解释

  评论区