题解 | #学分绩点#

学分绩点

https://www.nowcoder.com/practice/a0c09a7e0da04e728810a8aca7226b7b

#include<iostream>
using namespace std;

const int N = 1010;

int xuefen[N];

double jidian(double score) {
    double res = 0;
    if (score >= 90 && score <= 100) res = 4.0;
    else if (score >= 85 && score <= 89) res = 3.7;
    else if (score >= 82 && score <= 84) res = 3.3;
    else if (score >= 78 && score <= 81) res = 3.0;
    else if (score >= 75 && score <= 77) res = 2.7;
    else if (score >= 72 && score <= 74) res = 2.3;
    else if (score >= 68 && score <= 71) res = 2.0;
    else if (score >= 64 && score <= 67) res = 1.5;
    else if (score >= 60 && score <= 63) res = 1.0;
    else if (score < 60) res = 0;
    return res;
}

int main(void) {
    int n;
    cin >> n;
    int sum = 0;    //学分之和
    double xuefen_score = 0;
    for (int i = 0; i < n; i++) {
        cin >> xuefen[i];
        sum += xuefen[i];
    }
    for (int i = 0; i < n; i++) {
        int score;
        cin >> score;
        xuefen_score += jidian(score) * xuefen[i];
    }
    double GPA = xuefen_score / sum;
    printf("%.2f\n", GPA);

    return 0;
}

全部评论

相关推荐

offer多多的六边形战士很无语:看了你的博客,感觉挺不错的,可以把你的访问量和粉丝数在简历里提一下,闪光点(仅个人意见)
点赞 评论 收藏
分享
dongsheng66:如果想进大厂的话,在校经历没必要占这么大篇幅,可以把专业技能单独放一个专栏写,可以加个项目经历
点赞 评论 收藏
分享
点赞 收藏 评论
分享
牛客网
牛客企业服务