2871. 成绩统计
小蓝给学生们组织了一场考试,卷面总分为 100 分,每个学生的得分都是一个 0 到 100 的整数。
如果得分至少是 60 分,则称为及格。
如果得分至少为 85 分,则称为优秀。
请计算及格率和优秀率,用百分数表示,百分号前的部分四舍五入保留整数。
输入格式
输入的第一行包含一个整数 n,表示考试人数。
接下来 n 行,每行包含一个 0 至 100 的整数,表示一个学生的得分。
输出格式
输出两行,每行一个百分数,分别表示及格率和优秀率。
百分号前的部分四舍五入保留整数。
数据范围
对于 50% 的评测用例,1≤n≤100。
对于所有评测用例,1≤n≤10000。
输入样例:
7
80
92
56
74
88
100
0
输出样例:
71%
43%
代码
package com.xiang.lanqiao;
import java.util.Scanner;
/**
* @author snape
* @create 2021-12-10 10:11
*/
public class ResultsStatistical {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int num = scan.nextInt();
int[] score = new int[num];
double pass = 0.0;
double excellent = 0.0;
for (int i = 0; i < num; i++) {
score[i] = scan.nextInt();
if (score[i] >= 85){
excellent++;
}
if (score[i] >= 60){
pass++;
}
}
System.out.println(Math.round((pass / num)*100) + "%");
System.out.println(Math.round((excellent / num)*100) + "%");
scan.close();
}
}