解题思路:
注意事项:
参考代码:
import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int[] ns = new int[n]; int a = 0, b = 0, c = 0, d = 0, e = 0; ArrayList<Integer> list = new ArrayList<Integer>(); for (int i = 0; i < n; i++) { ns[i] = sc.nextInt(); if (ns[i] >= 90 && ns[i] <= 100) { a++; } if (ns[i] >= 80 && ns[i] <= 89) { b++; } if (ns[i] >= 70 && ns[i] <= 79) { c++; } if (ns[i] >= 60 && ns[i] <= 69) { d++; } if (ns[i] >= 0 && ns[i] <= 59) { e++; } } System.out.printf("%d %d %d %d %d \n", a, b, c, d, e); int max = Math.max(a, b); max = Math.max(max, c); max = Math.max(max, d); max = Math.max(max, e); System.out.println(max); for (int i = 0; i < ns.length; i++) { if (ns[i] >= 90 && ns[i] <= 100) { if (max == a) { list.add(ns[i]); } } if (ns[i] >= 80 && ns[i] <= 89) { if (max == b) { list.add(ns[i]); } } if (ns[i] >= 70 && ns[i] <= 79) { if (max == c) { list.add(ns[i]); } } if (ns[i] >= 60 && ns[i] <= 69) { if (max == d) { list.add(ns[i]); } } if (ns[i] >= 0 && ns[i] <= 59) { if (max == e) { list.add(ns[i]); } } } Collections.sort(list); Collections.reverse(list); for (int i = 0; i < list.size(); i++) { System.out.print(list.get(i) + " "); } } }
0.0分
2 人评分
C语言训练-求PI* (C语言代码)(正确结果竟然是谜一样的3.141591)浏览:1301 |
C语言程序设计教程(第三版)课后习题10.7 (C语言代码)浏览:639 |
C语言程序设计教程(第三版)课后习题4.9 (C语言代码)浏览:689 |
C语言训练-数字母 (C语言代码)浏览:582 |
不容易系列 (C语言代码)浏览:664 |
C语言程序设计教程(第三版)课后习题11.8 (C语言代码)浏览:869 |
K-进制数 (C语言描述,蓝桥杯)浏览:925 |
printf基础练习2 (C语言代码)浏览:503 |
格式化数据输出 (C语言代码)浏览:811 |
C语言程序设计教程(第三版)课后习题10.5 (C语言代码)浏览:946 |