First, solve the problem. Then, write the code. ” - John Johnson

It's not at all important to get it right the first time. It's vitally important to get it right the last time. ” - Andrew Hunt and David Thomas

Wednesday, July 16, 2014

Above Average.

Author : Jisan
Programming language : Java
Difficulty : Easy
Status : Accepted
Problem number : UVA-10370
http://uva.onlinejudge.org/index.php?option=onlinejudge&page=show_problem&problem=1311

Code:

import java.util.Scanner;

public class Uva_10370{
 
    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        int cases = s.nextInt();
        for(int i=0;i<cases;i++){
            int n=s.nextInt();
            int []jisan=new int[n];
            int sum=0;
            float avg=0;
            for(int j=0;j<jisan.length;j++){
                jisan[j]=s.nextInt();
                sum+=jisan[j];
            }
            avg=(float)sum/n;
            int count=0;
            for(int j=0;j<jisan.length;j++){
                if(jisan[j]>avg)
                    count++;
            }
            System.out.printf("%.3f%%%n", (float)count*100/n);
        }
    }
}

No comments:

Post a Comment