-
[C++] BOJ 1546번: 평균프로그래밍/알고리즘 PS 2024. 4. 1. 20:52
학교에서 진행하는 수업에서 공유받은 알고리즘 문제를 풀어보았다. 문제의 난이도는 브론즈 1이다.
문제 링크
https://www.acmicpc.net/problem/1546
문제 분석
입력된 모든 점수의 합을 구한 뒤, 평균을 두하고 입력값 중 최댓값인 M으로 평균값을 나누고 100을 곱하면 되는 문제이다.
전체 코드
#include <iostream> #include <algorithm> using namespace std; int scores[1001]; int N; int max_score = 1; double avg_score = 0.0; int main(void) { ios::sync_with_stdio(false); cin.tie(nullptr); cin >> N; for (int i = 0; i < N; i++) { cin >> scores[i]; max_score = max(max_score, scores[i]); avg_score += scores[i]; } avg_score /= N; avg_score = (avg_score / max_score) * 100; cout << avg_score << '\n'; return 0; }'프로그래밍 > 알고리즘 PS' 카테고리의 다른 글
[C++] Programmers: 성격 유형 검사하기 (1) 2024.04.01 [C++] BOJ 9012번: 괄호 (0) 2024.04.01 [C++] BOJ 2456번: 나는 학급회장이다 (0) 2024.03.29 [C++] BOJ 18870번: 좌표 압축 (0) 2024.03.28 [C++] BOJ 1032번: 명령 프롬프트 (0) 2024.03.28