解题思路:
注意事项:
参考代码:
import java.util.*; import java.util.concurrent.atomic.AtomicInteger; public class Main { public static void main(String[] args){ Scanner cin = new Scanner(System.in); int n = cin.nextInt(); Map<Integer, List<Integer>> map = new HashMap<>(); map.put(1, new ArrayList<>()); map.put(2, new ArrayList<>()); map.put(3, new ArrayList<>()); map.put(4, new ArrayList<>()); map.put(5, new ArrayList<>()); for(int i = 0; i < n; i++){ int grade = cin.nextInt(); if (grade >= 0 && grade <=59){ map.get(5).add(grade); }else if(grade >= 60 && grade <=69){ map.get(4).add(grade); }else if(grade >= 70 && grade <=79){ map.get(3).add(grade); }else if(grade >= 80 && grade <=89){ map.get(2).add(grade); }else if(grade >= 90 && grade <=100){ map.get(1).add(grade); } } int max = -1; int count = 0; List<Integer> maxList = null; for(int k :map.keySet()){ count ++; int size = map.get(k).size(); System.out.print(size); System.out.print(" "); if(max < size){ max = size; maxList = map.get(k); } if(count == 5){ System.out.println(); } } System.out.println(max); assert maxList != null; maxList.sort((o1, o2) -> o2 - o1); maxList.forEach(e -> { System.out.print(e); System.out.print(" "); }); } }
0.0分
1 人评分
剪刀石头布 (C语言代码)浏览:1519 |
矩阵转置 (C语言代码)浏览:855 |
C语言程序设计教程(第三版)课后习题8.3 (C语言代码)浏览:417 |
C语言程序设计教程(第三版)课后习题1.5 (C语言代码)浏览:559 |
C语言训练-字符串正反连接 (C语言代码)浏览:653 |
老王赛马 (C++代码)浏览:973 |
1202题解浏览:689 |
2004年秋浙江省计算机等级考试二级C 编程题(1) (C语言代码)浏览:617 |
简单的a+b (C语言代码)浏览:587 |
C语言程序设计教程(第三版)课后习题1.6 (C语言代码)浏览:549 |