본문 바로가기

algorithm

백준 1546번 평균

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;

}

 

'algorithm' 카테고리의 다른 글

백준 11660번 구간 합 구하기 5  (0) 2024.11.24
백준 11659번 구간 합 구하기  (0) 2024.11.17
백준 11720번 숫자의 합  (0) 2024.11.17
백준 4153번 직각삼각형  (0) 2024.11.03
백준 2920번 음계  (0) 2024.11.03