使用JAVA是对的不给分是怎么回事啊?
查看原帖
使用JAVA是对的不给分是怎么回事啊?
1406815
xiaobu321楼主2024/11/2 21:13
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int[] englishWordCount = new int[27];
        Integer max = null;
        for (int i = 1; i <= 4; i++) {
            String word = scanner.nextLine();
            for (int j = 0; j < word.length(); j++) {
                if (word.charAt(j) >= 'A' && word.charAt(j) <= 'Z') {
                    englishWordCount[word.charAt(j) % 26] += 1;
                }
            }
        }
        for (int i = 'A'; i <= 'Z'; i++) {
            if (max==null||max<englishWordCount[i % 26]){
                max = englishWordCount[i % 26];
            }
        }
        for (int i = max+1; i > 0; i--) {
            for (int j = 'A'; j <= 'Z'; j++) {
                //判断后面是否还有大于i的数
                boolean flag=false;
                for (int k = j+1; k <= 'Z'; k++) {
                    if (englishWordCount[k % 26]>=i){
                        flag=true;
                        break;
                    }
                }
                //////////
                int value = englishWordCount[j % 26];
                if (value>=i){
                    if (flag)
                        System.out.print("* ");
                    else
                        System.out.print("*");
                }else {
                    if (flag)
                        System.out.print("  ");
                    else
                        System.out.print(" ");
                }

                if (!flag){
                    break;
                }

            }
            System.out.println();
        }
        for (int i = 'A'; i <= 'Z'; i++) {
            if (i=='Z'){
                System.out.printf("%c",i);
            }else {
                System.out.printf("%c ",i);
            }

        }

    }
}

2024/11/2 21:13
加载中...