设为首页 加入收藏

TOP

HDU - 4802 - GPA (水题)
2018-10-21 14:12:49 】 浏览:34
Tags:HDU 4802 GPA 水题

题意:

计算GPA,输入一个数字和一个字符串,用 数字×字符串对应的数值

思路:

用map对应数值,要注意的是字符串为P或者N的时候,不计入结果

代码:

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

using namespace std;

map<string, double> mp;

int main() {
    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;
    int t;
    while (~scanf("%d", &t)) {
        double x, ans = 0.0, index = 0.0;
        string str;
        for (int i = 1; i <= t; i++) {
            cin >> x >> str;
            if (str == "P" || str == "N") continue;
            ans += x * mp[str];
            index += x;
        }
        if (index == 0) printf("0.00\n");
        else printf("%.2lf\n", ans / index);
    }

    return 0;
}
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇HDU - 4811 - Ball (思维) 下一篇agc007B - Construct Sequences(..

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目