Poj 2350 Above Average(精度控制)
来源:互联网 发布:centos开启snmp 编辑:程序博客网 时间:2024/04/30 06:59
一、Description
It is said that 90% of frosh expect to be above average in their class. You are to provide a reality check.
Input
The first line of standard input contains an integer C, the number of test cases. C data sets follow. Each data set begins with an integer, N, the number of people in the class (1 <= N <= 1000). N integers follow, separated by spaces or newlines, each giving the final grade (an integer between 0 and 100) of a student in the class.
Output
For each case you are to output a line giving the percentage of students whose grade is above average, rounded to 3 decimal places.
二、题解
本题难度不大,只需先求出平均值,然后再依个比较,算出比平均值大的个数,再除以总人数就得所求。要注意精度控制,保留小数点三位。这里用了DecimalFormat类,
三、java代码
二、题解
本题难度不大,只需先求出平均值,然后再依个比较,算出比平均值大的个数,再除以总人数就得所求。要注意精度控制,保留小数点三位。这里用了DecimalFormat类,
DecimalFormat
是 NumberFormat
的一个具体子类,用于格式化十进制数字。该类设计有各种功能,使其能够解析和格式化任意语言环境中的数,包括对西方语言、阿拉伯语和印度语数字的支持。它还支持不同类型的数,包括整数 (123)、定点数 (123.4)、科学记数法表示的数 (1.23E4)、百分数 (12%) 和金额 ($123)。所有这些内容都可以本地化。
三、java代码
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc=new Scanner(System.in); int[] a=new int[1000]; int m,i,sum,num; double average,per; int n=sc.nextInt(); while(n--!=0){ m=sc.nextInt(); sum=0; num=0; for(i=0;i<m;i++){ a[i]=sc.nextInt(); sum+=a[i]; } average=1.0*sum / m; for(i=0;i<m;i++){ if(a[i]>average) num++; } per=(1.0*num)/m *100; System.out.println(new java.text.DecimalFormat("0.000").format(per)+"%"); } } }
- Poj 2350 Above Average(精度控制)
- poj 2350 Above Average
- poj 2350 Above Average
- POJ 2350Above Average
- POJ 2350 Above Average(水~)
- 【输出%】poj 2350 Above Average
- POJ 2350 Above Average G++
- poj2350 Above Average(模拟)
- POJ 2350 Above Average(我的水题之路——%lf输出报错)
- Above Average
- Above Average
- Above Average
- Above Average
- Above Average
- zoj 1915 Above Average(水~)
- fjnu 1518 Above Average
- FZU 1629 Above Average
- zoj 1915 Above Average
- D - Warm up 2
- Ubuntu Trac Install
- 数据库联合主键
- Ubuntu 查看和杀死进程
- http协议
- Poj 2350 Above Average(精度控制)
- 【Java】Telnet 获取报头信息方法
- 修改文件件名
- 【Sesame】Server Installation 芝麻数据库服务器安装搭建
- CF-333D- Characteristics of Rectangles
- 秀丸
- Ubuntu的crontab定时任务
- Exchange Server 2010压力测试工具
- jquery easyui tabs 在table页上添加查询条件