프로그래밍 study/cpp study 백준

[백준] 4344번 평균은 넘겠지 C++ 문제 풀이 1D ARRY - 7

박재완 2021. 4. 23. 09:00
728x90
반응형

문제

대학생 새내기들의 90%는 자신이 반에서 평균은 넘는다고 생각한다. 당신은 그들에게 슬픈 진실을 알려줘야 한다.

입력

첫째 줄에는 테스트 케이스의 개수 C가 주어진다.

둘째 줄부터 각 테스트 케이스마다 학생의 수 N(1 ≤ N ≤ 1000, N은 정수)이 첫 수로 주어지고, 이어서 N명의 점수가 주어진다. 점수는 0보다 크거나 같고, 100보다 작거나 같은 정수이다.

출력

각 케이스마다 한 줄씩 평균을 넘는 학생들의 비율을 반올림하여 소수점 셋째 자리까지 출력한다.

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
//
//  main.cpp
//  4344
//
//  Created by 박재완 on 2021/03/27.
//
 
#include <iostream>
 
using namespace std;
 
int sample = 0, score[1001= {0,}, sum = 0 ;
double avarage = 0, percent = 0, overavreag_case = 0, student = 0;
 
 
int main(int argc, const char * argv[]) {
    cin >> sample;
    for(int t = 0; t < sample ; t++){
        cout.setf(ios::fixed);
        cout.precision(3);
        overavreag_case = 0;
        sum = 0;
        avarage = 0;
        cin >> student;
        for(int i =0 ; i < student ; i ++){cin>>score[i]; sum += score[i];}
        avarage = sum/student;//avareage add
        for(int r =0 ; r < student ; r ++){if(avarage < score[r]){overavreag_case++;}}
        percent = (overavreag_case/student)*100;
        cout <<percent<<"%"<<endl;
        cout.unsetf(ios::fixed);
    }
      
    
    /*test output
    for(int i = 0 ; i < student ; i ++){
        cout << score[i] << endl;
    }*/
    return 0;
}
cs

 

728x90
반응형