합리적 낙관주의자

SWEA [D3] 10505번: 소득 불균형 본문

Computer Thinking 🌟/Algorithm 📝

SWEA [D3] 10505번: 소득 불균형

sroa.chin 2020. 8. 31. 23:54

swexpertacademy.com/main/code/problem/problemSolverCodeDetail.do

 

SW Expert Academy

SW 프로그래밍 역량 강화에 도움이 되는 다양한 학습 컨텐츠를 확인하세요!

swexpertacademy.com

10분


import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
 
public class Solution {
    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
         
        int TC = Integer.parseInt(br.readLine());
        int N, cnt, income[];
        long total, avg;
        StringTokenizer st = null;
        for (int testCase = 1; testCase <= TC; testCase++) {
            cnt = 0; total = 0; avg = 0;
            N = Integer.parseInt(br.readLine());
            income = new int [N];
            st = new StringTokenizer(br.readLine());
             
            for (int i = 0; i < N; i++) {
                income[i] = Integer.parseInt(st.nextToken());
                total+=income[i];
            }
            avg = total/N;
            for (int i = 0; i < N; i++) {
                if(avg >= income[i]) cnt++;
            }
            System.out.println("#" + testCase+" "+cnt);
        }//end of testCase 
    }//end of main
}//end of class
/*
3
7
15 15 15 15 15 15 15
10
1 1 1 1 1 1 1 1 1 100
7
2 7 1 8 2 8 4
*/