现在的位置: 首页 > 综合 > 正文

hdu – 4802 – GPA(模拟)

2019年08月30日 ⁄ 综合 ⁄ 共 787字 ⁄ 字号 评论关闭

题意:学分和成绩换为平均绩点,公式:(c1 * s1 + c2 * s2 + ... + cN * sN) / (c1 + c2 + ... + cN)(1 <= N <= 1000)。

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4802

——>>13年南京区赛签到题。。

注:按“通过”与“不通过”的方式来计算成绩的科目忽略。。

#include <cstdio>
#include <map>
#include <string>
#include <iostream>
#include <cmath>

using std::cin;
using std::string;
using std::map;

const double EPS = 1e-8;

int N;
map<string, double> mp;

int Dcmp(double x)
{
    if (fabs(x) < EPS) return 0;
    return x > 0 ? 1 : -1;
}

void Init()
{
    mp["A"] = 4.0;
    mp["A-"] = 3.7;
    mp["B+"] = 3.3;
    mp["B"] = 3.0;
    mp["B-"] = 2.7;
    mp["C+"] = 2.3;
    mp["C"] = 2.0;
    mp["C-"] = 1.7;
    mp["D"] = 1.3;
    mp["D-"] = 1.0;
    mp["F"] = 0.0;
}

void Read()
{
    double c, sum = 0, csum = 0;
    string str;

    for (int i = 0; i < N; ++i)
    {
        cin >> c >> str;
        if (str[0] == 'P' || str[0] == 'N') continue;
        sum += c * mp[str];
        csum += c;
    }
    Dcmp(csum) == 0 ? puts("0.00") : printf("%.2f\n", sum / csum);
}

int main()
{
    Init();
    while (scanf("%d", &N) == 1)
    {
        Read();
    }

    return 0;
}

抱歉!评论已关闭.