小技巧 判断 全部为零 用sign和所有元素依次取或
排除最大项和最小项 直接排序后取中间的四个元素
http://poj.org/problem?id=3507
1 #include <iostream> 2 #include <stdio.h> 3 #include <algorithm> 4 using namespace std; 5 6 int main() 7 { 8 freopen("in.txt", "r", stdin); 9 int a[6]; 10 double sum; 11 bool sign = 0; 12 while (1) 13 { 14 sign = 0; 15 sum = 0; 16 for (int i = 0; i < 6; i++) 17 { 18 cin >> a[i]; 19 sign |= a[i]; 20 } 21 if (!sign) break; 22 sort(a, a+6); 23 for (int i = 1; i < 5; i++) 24 { 25 sum += a[i]; 26 } 27 cout << sum / 4 << endl; 28 } 29 return 0; 30 }
时间: 2024-08-28 10:59:51