Baekjoon/단계별로 풀어보기

[BOJ/백준] 4344번 평균은 넘겠지 C++ 문제 풀이

728x90

단계별로 풀어보기 - 1차원 배열 - [7단계] 4344번

문제

문제 링크 : www.acmicpc.net/problem/4344

 

4344번: 평균은 넘겠지

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

www.acmicpc.net

입력 복사 : 

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

 

CODE

#include <iostream>
using namespace std;

int main() {
	int c, n, num;
	int avg;
	int score[1000] = { 0 };
	double result;

	cin >> c;
	for (int i = 0; i < c; i++) {
		avg = 0;
		num = 0;
		cin >> n;

		for (int j = 0; j < n; j++) {
			cin >> score[j];
			avg = avg + score[j];
		}
		avg = avg / n;
		for (int j = 0; j < n; j++) {
			if (score[j] > avg)
				num++;
		}
		result = (double)num / n * 100;

		cout << fixed;
		cout.precision(3);
		cout << result << "%" << endl;
	}
}

 

결과

 

 

 

 

728x90