付永康


私信TA

用户名:dotcpp0605582

访问量:825

签 名:

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

  自我简介:

解题思路:

注意事项:

参考代码:

import java.util.*;

public class TT1500 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] arr = new int[n];
        ArrayList<Integer> A = new ArrayList<Integer>();
        ArrayList<Integer> B = new ArrayList<Integer>();
        ArrayList<Integer> C = new ArrayList<Integer>();
        ArrayList<Integer> D = new ArrayList<Integer>();
        ArrayList<Integer> E = new ArrayList<Integer>();

        for (int i = 0; i < n; i++) {
            arr[i] = sc.nextInt();
        }

        Map<String,Integer> map = new HashMap<String,Integer>();

        for (int i = 0; i < arr.length; i++) {
            if (arr[i] >= 90) {
                A.add(arr[i]);
                if (map.containsKey("A")) {
                    map.put("A",map.get("A") + 1);
                } else {
                    map.put("A",1);
                }
            } else if (arr[i] <= 89 && arr[i] >= 80) {
                B.add(arr[i]);
                if (map.containsKey("B")) {
                    map.put("B",map.get("B") + 1);
                } else {
                    map.put("B",1);
                }
            } else if (arr[i] <= 79 && arr[i] >= 70) {
                C.add(arr[i]);
                if (map.containsKey("C")) {
                    map.put("C",map.get("C") + 1);
                } else {
                    map.put("C",1);
                }
            } else if (arr[i] <= 69 && arr[i] >= 60) {
                D.add(arr[i]);
                if (map.containsKey("D")) {
                    map.put("D",map.get("D") + 1);
                } else {
                    map.put("D",1);
                }
            } else {
                E.add(arr[i]);
                if (map.containsKey("E")) {
                    map.put("E",map.get("E") + 1);
                } else {
                    map.put("E",1);
                }
            }
        }

        //给list集合从小到大排序
        Collections.sort(A);
        Collections.sort(B);
        Collections.sort(C);
        Collections.sort(D);
        Collections.sort(E);

        //通过set遍历map后找最大value
        int max = 0;
        Set<String> set = map.keySet();
        for (String i : set) {
            System.out.print(map.get(i) + " ");
            if (max < map.get(i)) {
                max = map.get(i);}
        }

        String key = "";
        //通过value找key
        for (Map.Entry entry : map.entrySet()) {
            if (entry.getValue().equals(max)) {
                key = entry.getKey() + "";
            }
        }

        System.out.println();
        System.out.println(max);

        if (key.equals("A")) {
            for (int i = A.size() - 1; i >= 0; i--) {
                System.out.print(A.get(i) + " ");
            }
        } else if (key.equals("B")) {
            for (int i = B.size() - 1; i >= 0; i--) {
                System.out.print(B.get(i) + " ");
            }
        } else if (key.equals("C")) {
            for (int i = C.size() - 1; i >= 0; i--) {
                System.out.print(C.get(i) + " ");
            }
        } else if (key.equals("D")) {
            for (int i = D.size() - 1; i >= 0; i--) {
                System.out.print(D.get(i) + " ");
            }
        } else {
            for (int i = E.size() - 1; i >= 0; i--) {
                System.out.print(E.get(i) + " ");
            }
        }
    }
}


 

0.0分

1 人评分

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

编程语言转换

万能编程问答  

代码解释器

代码纠错

SQL生成与解释

  评论区