试题 算法提高 分数统计

Lan
Lan
2020-03-14 / 0 评论 / 448 阅读 / 正在检测是否收录...
温馨提示:
本文最后更新于2020年03月14日,已超过1505天没有更新,若内容或图片失效,请留言反馈。
资源限制
时间限制:1.0s   内存限制:512.0MB
问题描述
  2016.4.5已更新此题,此前的程序需要重新提交。
问题描述
  给定一个百分制成绩T,将其划分为如下五个等级之一:
  90~100为A,80~89为B,70~79为C,60~69为D,0~59为E
  现在给定一个文件inp,文件中包含若干百分制成绩(成绩个数不超过100),请你统计五个等级段的人数,并找出人数最多的那个等级段,按照从大到小的顺序输出该段中所有人成绩(保证人数最多的等级只有一个)。要求输出到指定文件oup中。
输入格式
  若干0~100的正整数,用空格隔开
输出格式
  第一行为5个正整数,分别表示A,B,C,D,E五个等级段的人数
  第二行一个正整数,表示人数最多的等级段中人数
  接下来一行若干个用空格隔开的正整数,表示人数最多的那个等级中所有人的分数,按从大到小的顺序输出。
样例输入
100 80 85 77 55 61 82 90 71 60
样例输出
2 3 2 2 1
3
85 82 80
import java.util.*;
public class fenshutongji {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		int a=0,b=0,c=0,d=0,e=0;
		int n = sc.nextInt();
		int[]list = new int[n];
		for (int i = 0; i < list.length; i++) {
			list[i]=sc.nextInt();
		}
		ArrayList<Integer> result0 = new ArrayList<Integer>();
		ArrayList<Integer> result1 = new ArrayList<Integer>();
		ArrayList<Integer> result2 = new ArrayList<Integer>();
		ArrayList<Integer> result3 = new ArrayList<Integer>();
		ArrayList<Integer> result4 = new ArrayList<Integer>();
		
		for (int i = 0; i < list.length; i++) {
			if (list[i]<=100&&list[i]>=90) {
				result0.add(list[i]);
				a++;
			}else if (list[i]<=89&&list[i]>=80) {
				result1.add(list[i]);
				b++;
			}else if (list[i]<=79&&list[i]>=70) {
				result2.add(list[i]);
				c++;
			}else if (list[i]<=69&&list[i]>=60) {
				result3.add(list[i]);
				d++;
			}else if (list[i]<=59&&list[i]>=0) {
				result4.add(list[i]);
				e++;
			}
		}
		int []index = {a,b,c,d,e};
		for (int i = 0; i < index.length; i++) {
			System.out.print(index[i]+" ");
		}
		int temp=0,max=0;
		for (int i = 0; i < index.length; i++) {
			if (index[i]>temp) {
				temp = index[i];
				max = i;
			}
		}
		System.out.println("
"+temp);
		//应题目要求从大到小输出,然后就。。。先顺序排序,再逆转列表
		if (max==0) {
			Collections.sort(result0);
			Collections.reverse(result0);
			for (int i = 0; i < result0.size(); i++) {
				System.out.print(result0.get(i)+" ");
			}
		}else if (max==1) {
			Collections.sort(result1);
			Collections.reverse(result1);
			for (int i = 0; i < result1.size(); i++) {
				System.out.print(result1.get(i)+" ");
			}
		}else if (max==2) {
			Collections.sort(result2);
			Collections.reverse(result2);
			for (int i = 0; i < result2.size(); i++) {
				System.out.print(result2.get(i)+" ");
			}
		}else if (max==3) {
			Collections.sort(result3);
			Collections.reverse(result3);
			for (int i = 0; i < result3.size(); i++) {
				System.out.print(result3.get(i)+" ");
			}
		}else if (max==4) {
			Collections.sort(result4);
			Collections.reverse(result4);
			for (int i = 0; i < result4.size(); i++) {
				System.out.print(result4.get(i)+" ");
			}
		}
	}

}


0

评论 (0)

取消