写在前面

  • 细节处理
  • 分数计算有坑
  • 合法区间判断
  • 结果分数四舍五入
  • 比较简单,细节处理耗费时间,10分钟内a题

测试用例

input: 
6 50
42 49 49 35 38 41
36 51 50 28 -1 30
40 36 41 33 47 49
30 250 -25 27 45 31
48 0 0 50 50 1234
43 41 36 29 42 29

output :
42
33
41
31
37
39

ac代码

  • 其中,bz_score 类型定义错误,导致输出结果异常情况
#include<cmath>
#include<iostream>
using namespace std;

int main()
{
int n, m;
scanf("%d%d",&n,&m);

for(int i=0; i<n; i++)
{
double score = 0.0;
int bz_score = 0, max_v=0, min_v=100, cur_v =0, cnt = -2;
scanf("%d", &bz_score);

for(int j=1; j<n; j++)
{
scanf("%d", &cur_v);
if((cur_v>=0)&&(cur_v<=m))
{
cnt++;
score += cur_v;
if(cur_v>max_v) max_v = cur_v;
if(cur_v<min_v) min_v = cur_v;
}
}
score = (bz_score + (score-min_v-max_v)/cnt)/2;
printf("%.0f\n", round(score));
}
return 0;
}

参考代码

  • 代码逻辑几乎雷同
#include <iostream>
using namespace std;
int main() {
int n, m;
cin >> n >> m;
for (int i = 0; i < n; i++) {
int g2, g1 = 0, cnt = -2, temp, maxn = -1, minn = m + 1;
cin >> g2;
for (int j = 0; j < n-1; j++) {
cin >> temp;
if (temp >= 0 && temp <= m) {
if (temp > maxn) maxn = temp;
if (temp < minn) minn = temp;
g1 += temp;
cnt++;
}
}
cout << int((((g1 - minn - maxn) * 1.0 / cnt) + g2) / 2 + 0.5) << endl;
}
return 0;
}