hdu - 4802 - GPA(模拟)

题意:学分和成绩换为平均绩点,公式:(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;
}


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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值