10370-above Average
Time limit:3.000 seconds
Http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem &problem=1311
It is said this 90% of Frosh expect to being above average in their class. You are are to provide a reality check.
The 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) of a Studen T in the class. For each case you are to output a line giving the percentage of students whose grade are above average, rounded to 3 Decima L places.
Sample Input
5
5 of
7,
3
, 3, 9, 100, 99, 98 97, 96 95.
Output for Sample Input
40.000%
57.143%
33.333%
66.667%
55.556%
Complete code:
/*0.012s*/
#include <cstdio>
int num[1010];
int main (void)
{
int i, T, N, average, count;
scanf ("%d", &t);
while (t--)
{
scanf ("%d", &n);
Average = 0;
for (i = 0; i < n; i++)
{
scanf ("%d", &num[i]);
Average + = Num[i];
}
Average/= n;///because it is greater than, so no problem ~
count = 0;
for (i = 0; i < n; i++)
if (Num[i] > average) count++;
printf ("%.3f%%\n", (double) count/n *);
return 0;
}
See more highlights of this column: http://www.bianceng.cnhttp://www.bianceng.cn/Programming/sjjg/