一、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类,

DecimalFormatNumberFormat 的一个具体子类,用于格式化十进制数字。该类设计有各种功能,使其能够解析和格式化任意语言环境中的数,包括对西方语言、阿拉伯语和印度语数字的支持。它还支持不同类型的数,包括整数 (123)、定点数 (123.4)、科学记数法表示的数 (1.23E4)、百分数 (12%) 和金额 ($123)。所有这些内容都可以本地化。

System.out.println(new java.text.DecimalFormat("0.000").format(per)+"%");

三、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(精度控制)的更多相关文章

  1. POJ 2350 Above Average

    Description It is said that 90% of frosh expect to be above average in their class. You are to provi ...

  2. C++ 数据类型及相关问题 及输出精度控制

    1.有哪些数据类型? 2.数据类型在不同的编译器会有不同的位宽,如何得知? 使用如下命令: cout<<sizeof(int)<<endl; cout<<sizeo ...

  3. POI使用:用poi接口不区分xls/xlsx格式解析Excel文档(41种日期格式解析方法,5种公式结果类型解析方法,3种常用数值类型精度控制办法)

    一.使用poi解析excel文档 注:全部采用poi接口进行解析,不需要区分xls.xlsx格式,不需要判断文档类型. poi中的日期格式判断仅支持欧美日期习惯,对国内的日期格式并不支持判断,怎么办? ...

  4. 文件重定向,getline()获取一样,屏幕输出流,格式控制符dec,oct,hex,精度控制setprecision(int num),设置填充,cout.width和file(字符),进制输入

     1.在window下的命令重定向输出到文件里 2.将内容输入到某个文件里的方式:命令<1.txt (使用1.txt中的命令) 3.读取文件里的名,然后将命令读取最后输出到文件里.命令< ...

  5. Java 浮点数精度控制

    1.String.format​(String format,Object… args) Java中用String.format()来控制输出精度, format参数用来设置精度格式, args参数代 ...

  6. poj 1517 u Calculate e(精度控制+水题)

    一.Description A simple mathematical formula for e is e=Σ0<=i<=n1/i! where n is allowed to go t ...

  7. POJ 1064 Cable master (二分法+精度控制)

    Cable master Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 65358   Accepted: 13453 De ...

  8. cout输出控制——位数和精度控制

    刷到一道需要控制输出精度和位数的题目 刚开始以为单纯使用 iomanip 函数库里的 setprecision 就可以,但 OJ 给我判了答案错误,后来一想这样输出并不能限制位数只能限制有效位数. 比 ...

  9. 谈谈关于Python里面小数点精度控制的问题

    基础 浮点数是用机器上浮点数的本机双精度(64 bit)表示的.提供大约17位的精度和范围从-308到308的指数.和C语言里面的double类型相同.Python不支持32bit的单精度浮点数.如果 ...

随机推荐

  1. iOS设备获取总结

    1.获取iOS设备的各种信息 // 这个方法后面会列出来 NSString *deviceName = [self getDeviceName]; NSLog(@"设备型号-->%@& ...

  2. can not find java.util.map java.lang.Double问题

    mybatis      @Param注解和ParamType属性不能共存

  3. [Symfony\Component\Config\Definition\Exception\InvalidConfigurationException] The child node "db_driver" at path "fos_user" must be configured.

    $ php bin/console server:run [Symfony\Component\Config\Definition\Exception\InvalidConfigurationExce ...

  4. Android 主线程和子线程通信问题

        Android 如今不支持View在子线程中创建及调用其方法.假设要实现子线程内容更新之后.将结果及时反馈到主线程中,该怎样出来呢?     能够在主线程中创建Handler来实现. 这样子线 ...

  5. Write 语句

    ABAP Write 语句 转载▼http://blog.sina.com.cn/s/blog_5ccd375b0100ghhi.html   1.Write 叙述 ABAP/4 用来在屏幕上输出数据 ...

  6. 通过GPRS将GPS数据上传到OneNet流程

    AT OK AT+CGCLASS="B" OK AT+CGDCONT=1,"IP","CMNET" OK AT+CGATT=1 OK AT+ ...

  7. 很详细、很移动的Linux makefile 教程

    近期在学习Linux下的C编程,买了一本叫<Linux环境下的C编程指南>读到makefile就越看越迷糊,可能是我的理解能不行. 于是google到了以下这篇文章.通俗易懂.然后把它贴出 ...

  8. CommonJS与AMD、CMD

    随着JS模块化编程的发展,处理模块之间的依赖关系变得至关重要,随后诞生了CommonJS.AMD与CMD规范,但es6的import/export能代替他们,但因为本人所使用的webpack也支持前三 ...

  9. min/max优化,count ,group by

    min/max优化 在表中,一般都是经过优化的. 如下地区表 id area pid 1 中国 0 2 北京 1 ... 3115 3113 我们查min(id), id是主键,查Min(id)非常快 ...

  10. LINQ 学习路程 -- 查询操作 Select, SelectMany

    IList<Student> studentList = new List<Student>() { , StudentName = "John" }, , ...