algorithm

백준 1546번 평균

YOU__NAVI 2024. 11. 17. 01:20

https://www.acmicpc.net/problem/1546

 

아이디어:

1. (과목별 점수) / (최고점) * 100 의 새로운 평균

2. {(A / max * 100) + (B / max * 100) + (C / max * 100)} / 3 = {(A + B + C) / max * 100 / 3}

3. 과목별 점수는 배열로 저장받고 총 합을 구해준다.

4. 마지막에 수식 적용

 

// 1546

#include <iostream>
#include <string>

using namespace std;

int main() {

	ios::sync_with_stdio(false);
	cin.tie(NULL);

	int n, max = 0;
	int score[1000];
	float answer = 0;

	cin >> n;

	for (int i = 0; i < n; i++) {
		
		cin >> score[i];

		if (max < score[i])
			max = score[i];

		answer += score[i];

	}

	answer = answer * 100 / max / n;
	cout << answer;

	return 0;

}