Skip to content

11241: 【原1241】欢总的GPA

题目

题目描述

author: Online Judge 原OJ链接:https://acm.sjtu.edu.cn/OnlineJudge-old/problem/1241

Description

欢总像你们这么大时也是很关心自己的GPA的,但是欢总选的课太多了,手算GPA太麻烦了,所以请你来帮欢总写一个方便的GPA计算器吧!

上海交通大学本科生出国GPA计算标准

01级及以后的本科毕业生:

[95,100] A+ 4.3

[90,95) A 4.0

[85,90) A- 3.7

[80,85) B+ 3.3

[75,80) B 3.0

[70,75) B- 2.7

[67,70) C+ 2.3

[65,67) C 2.0

[62,65) C- 1.7

[60,62) D 1.0

Input Format

第一行,一个整数N,所选课程总数。 第二到N+1行,每行一个整数(60到100之间),各门课程的分数

Output Format

一个浮点数,平均GPA(保留两位小数)

保留两位小数方法:

#include <iomanip>

程序中

double gpa;

cout << fixed << setprecision(2) << gpa;

Sample Input

2
92
80

Sample Output

3.65

ligongzzz's solution

#include "iostream"
#include "cstdio"
using namespace std;

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

    double TotalGPA = 0.0;

    for (int i = 0; i < N; ++i) {
        int temp;
        scanf("%d",&temp);

        if (temp >= 95) {
            TotalGPA += 4.3;
        }
        else if (temp >= 90) {
            TotalGPA += 4.0;
        }
        else if (temp >= 85) {
            TotalGPA += 3.7;
        }
        else if (temp >= 80) {
            TotalGPA += 3.3;
        }
        else if (temp >= 75) {
            TotalGPA += 3.0;
        }
        else if (temp >= 70) {
            TotalGPA += 2.7;
        }
        else if (temp >= 67) {
            TotalGPA += 2.3;
        }
        else if (temp >= 65) {
            TotalGPA += 2.0;
        }
        else if (temp >= 62) {
            TotalGPA += 1.7;
        }
        else if (temp >= 60) {
            TotalGPA += 1.0;
        }
    }

    printf("%.2f", TotalGPA / N);

    return 0;
}

skyzh's solution

#include <iostream>
#include <iomanip>

using namespace std;

int main() {
    int SCORE_MAP[101] = { 0 };
    for (int i = 60; i < 62; i++) SCORE_MAP[i] = 10;
    for (int i = 62; i < 65; i++) SCORE_MAP[i] = 17;
    for (int i = 65; i < 67; i++) SCORE_MAP[i] = 20;
    for (int i = 67; i < 70; i++) SCORE_MAP[i] = 23;
    for (int i = 70; i < 75; i++) SCORE_MAP[i] = 27;
    for (int i = 75; i < 80; i++) SCORE_MAP[i] = 30;
    for (int i = 80; i < 85; i++) SCORE_MAP[i] = 33;
    for (int i = 85; i < 90; i++) SCORE_MAP[i] = 37;
    for (int i = 90; i < 95; i++) SCORE_MAP[i] = 40;
    for (int i = 95; i <= 100; i++) SCORE_MAP[i] = 43;
    long long sum = 0;
    int N;
    cin >> N;
    int tmp;
    for (int i = 0; i < N; i++) {
        cin >> tmp;
        sum += SCORE_MAP[tmp];
    }
    cout << fixed << setprecision(2) << (double) sum / N / 10.0 << endl;
    return 0;
}