前往小程序,Get更优阅读体验!
立即前往
发布
社区首页 >专栏 >试题 算法提高 分数统计

试题 算法提高 分数统计

作者头像
SingYi
发布2022-07-13 18:35:15
发布2022-07-13 18:35:15
22800
代码可运行
举报
文章被收录于专栏:Lan小站Lan小站
运行总次数:0
代码可运行

资源限制

时间限制: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

代码语言:javascript
代码运行次数:0
复制
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)+" ");
			}
		}
	}

}
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档