0%

C++ 台中區 106-1 計算多個整數的平均值、最大值、最小值

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include<iostream>
#include<cstdio>
using namespace std;
#define INF 1000000000

long long round(long long a){
return (a+5)/10;
}

int main(){
long long n,sum=0,mx=-INF,mn=INF,t;
cin>>n;
for(int i=0;i<n;i++){
cin>>t;
mx=max(mx,t);
mn=min(mn,t);
sum+=t;
}
long long aver=round(sum*1000/n);
cout<<aver/100<<".";
printf("%02lld\n",aver%100);
cout<<mx<<"\n"<<mn<<"\n";
return 0;
}