63
풀이
입력받은 배열 내 최댓값을 찾고 주어진 식대로 계산하여 출력하면 됩니다.
코드
C
#include <stdio.h>
int main () {
int n, i;
double all = 0, max = 0;
double score[1000];
scanf("%d", &n);
for(i = 0; i < n; i++){
scanf("%lf", &score[i]);
if(max < score[i]){
max = score[i];
}
}
for(i = 0; i < n; i++){
all += score[i]/max*100;
}
printf("%lf", all/(double)n);
return 0;
}
C++
#include <iostream>
using namespace std;
int main () {
int n;
double all = 0, max = 0;
double score[1000];
cin>>n;
for(int i = 0; i < n; i++){
cin>>score[i];
if(max < score[i]){
max = score[i];
}
}
for(int i = 0; i < n; i++){
all += score[i]/max*100;
}
cout<<all/(double)n;
return 0;
}
Java
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
double all = 0, max = 0;
int n = sc.nextInt();
double score[] = new double[n];
for(int i = 0; i < n; i++){
score[i] = sc.nextInt();
if(max < score[i]){
max = score[i];
}
}
for(int i = 0; i < n; i++){
all += score[i]/max*100;
}
System.out.println(all/(double)n);
}
}
Python
n = int(input())
score = list(map(int, input().split()))
max = max(score)
all = 0
for s in score:
all += s/max*100;
print(all/n)
문제 출처
https://www.acmicpc.net/problem/1546