题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2014
题目大意:给你 n 个数,去掉 max 和 min ,求平均数
解题思路:
很水,边记录分数,边记录最边值域
代码:
1 #include<iostream> 2 #include<cmath> 3 #include<iomanip> 4 #include<algorithm> 5 using namespace std; 6 int num; 7 int main() 8 { 9 int n; 10 while(cin >> n) 11 { 12 int x; 13 int max = -1; 14 int min = 200; 15 double sum = 0; 16 for(int i = 0; i < n; i ++) 17 { 18 cin >> x; 19 if(x > max) 20 max = x; 21 if(x <min) 22 min = x; 23 sum += x; 24 } 25 cout << fixed << setprecision(2) << (sum - max - min) / (n - 2) << endl; 26 } 27 }
原文地址:https://www.cnblogs.com/mimangdewo-a1/p/9374552.html
时间: 2024-10-17 15:47:29