PAT Basic Level 1077 互评成绩计算 (20 分)

题目链接:

https://pintia.cn/problem-sets/994805260223102976/problems/994805262303477760

AC代码:

#include <bits/stdc++.h>
using namespace std;

int main(){
    int N,M;
    scanf("%d%d",&N,&M);
    int n=N;
    while(n--){
        double teach_;
        scanf("%lf",&teach_);
        double sum=0;//学生给出的合法总分之和
        double Min=110;
        double Max=0;
        int cnt=0;//学生给出的合法分数个数
        for(int i=0;i<N-1;i++){
            double tmp;
            scanf("%lf",&tmp);
            if(tmp<=M&&tmp>=0){
                if(tmp<=Min)
                    Min=tmp;
                if(tmp>=Max)
                    Max=tmp;
                sum+=tmp;
                cnt++;
            }
        }
        double ave=(sum-Max-Min)/(cnt-2);
        int result=(ave+teach_)/2;
        double result_=(ave+teach_)/2;
        if(result_-result>=0.50){
            printf("%d\n",result+1);
        }
        else{
            printf("%d\n",result);
        }

    }
    return 0;
}

 二刷:

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
using namespace std;

int main(){
    int N,M;
    scanf("%d%d",&N,&M);
    for(int i=0;i<N;i++){
        double sum=0;
        int cnt=0;
        double MAX=0,MIN=1000;
        double tea;
        scanf("%lf",&tea);
        for(int j=1;j<N;j++){
            double tmp;
            scanf("%lf",&tmp);
            if(tmp>=0&&tmp<=M){
                sum+=tmp;
                cnt++;
                if(MAX<tmp) MAX=tmp;
                if(MIN>tmp) MIN=tmp;
            }
        }
        sum=sum-MAX-MIN;
        cnt=cnt-2;
        double scr=sum/cnt;
        double defen=(scr+tea)/2;
        int defen1=(scr+tea)/2;
        if(defen-defen1>=0.5){
            defen1+=1;
        }
        printf("%d\n",defen1);
    }
    return 0;
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值