uva: 10370 – Above Average

10370 - Above Average
Root :: Contest Volumes (10000...) :: Volume 103 (10300-10399)

Solution in Java -

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Scanner;

class Main_10370_AboveAverage {

    public static void main(String[] args) {
        
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        Scanner sc = new Scanner(br);
        
        int testCases = sc.nextInt();
        
        for(int tc=1; tc<= testCases; tc++)
        {
            
            int N = sc.nextInt();
            int[] grades = new int[N+1];
            long sum=0;
            float avg=0,percent=0;
            
            
            for(int i=1;i<=N;i++)
            {
                grades[i] = sc.nextInt();
                sum+= grades[i];                        
            }
            
            Arrays.sort(grades);
            avg = sum / N;            
            for(int i=1; i<=N;i++)
            {
                if(Float.compare(grades[i],avg) > 0 )
                {
                    percent = ((float) ((N-i)+1) / N) * 100 ;
                    break;
                }
            }
            
            System.out.printf("%.3f",percent);        
            System.out.println("%");
        }

    }

}

/*
* input
5
5 50 50 70 80 100
7 100 95 90 80 70 60 50
3 70 90 80
3 70 90 81
9 100 99 98 97 96 95 94 93 91

output
40.000%
57.143%
33.333%
66.667%
55.556%
*/

 

Advertisements

About M Moniruzzaman
A passionate software engineer, have been developing applications on various platforms such as Android, iPhone, .Net (C#) technologies and web based ASP.NET, PHP, JavaScript, jQuery technologies for more than 10 years. Especially I have expertise on developing applications for Android and iPhone, as well as service oriented, client-server based applications where clients will be reside on Android/iPhone that communicate with WCF(.NET) service hosted on server. I have completed certification in Microsoft Certified Professional Developer (MCPD) on .Net 4 . I have completed my graduation in -- B.Sc. (Engineering) in Computer Science and Engineering, ShahJalal University of Science and Technology, Bangladesh. Thanks, M. Moniruzzaman (Zaman)

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: