GPA HDU 4802

GPA
Time Limit: 1000msMemory Limit: 32768KB This problem will be judged on HDU. Original ID: 4802
64-bit integer IO format: %I64d Java class name: Main
Prev Submit Status Statistics Next
In college, a student may take several courses. for each course i, he earns a certain credit (ci), and a mark ranging from A to F, which is comparable to a score (si), according to the following conversion table

The GPA is the weighted average score of all courses one student may take, if we treat the credit as the weight. In other words,

An additional treatment is taken for special cases. Some courses are based on “Pass/Not pass” policy, where stude nts earn a mark “P” for “Pass” and a mark “N” for “Not pass”. Such courses are not supposed to be considered in computation. These special courses must be ignored for computing the correct GPA.
Specially, if a student’s credit in GPA computation is 0, his/her GPA will be “0.00”.
Input
There are several test cases, please process till EOF.
Each test case starts with a line containing one integer N (1 <= N <= 1000), the number of courses. Then follows N lines, each consisting the credit and the mark of one course. Credit is a positive integer and less than 10.
Output
For each test case, print the GPA (rounded to two decimal places) as the answer.
Sample Input
5
2 B
3 D-
2 P
1 F
3 A
2
2 P
2 N
6
4 A
3 A
3 A
4 A
3 A
3 A
Sample Output
2.33
0.00
4.00
Source
2013ACM/ICPC亚洲区南京站现场赛——题目重现

#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<string>
#include<algorithm>
#include<stack>
#include<queue>
#include<cctype>
using namespace std;
const int MAX = 999999;
const double Eps = 1e-12;
const double PI = acos(-1.0);
int gcd(int x, int y)
{
    return x%y == 0 ? y : gcd(y, x%y);
}
//double gpa[20]=()
char str0[20][20] = { "0","A","A-","B+","B","B-","C+","C","C-","D","D-","F" };
int main()
{
    int t;
    while (cin >> t)
    {
        double sum = 0, sum2 = 0, a;
        char str[10];
        //getchar();
        while (t--)
        {
            /*
            2 B
            3 D-
            2 P
            1 F
            3 A
            2.33
            */

            scanf("%lf %s", &a, &str);
            //sum2 += a;
            if (!strcmp(str0[1], str))
            {
                sum += a*4.0;
                sum2 += a;
            }

            else if (!strcmp(str0[2], str))
            {
                sum += a*3.7;
                sum2 += a;
            }

            else if (!strcmp(str0[3], str))
            {
                sum += a*3.3;
                sum2 += a;
            }

            else if (!strcmp(str0[4], str))
            {
                sum += a*3.0;
                sum2 += a;

            }

            else if (!strcmp(str0[5], str))
            {
                sum += a*2.7;
                sum2 += a;
            }

            else if (!strcmp(str0[6], str))
            {
                sum += a*2.3;
                sum2 += a;
            }

            else if (!strcmp(str0[7], str))
            {
                sum += a*2.0;
                sum2 += a;
            }

            else if (!strcmp(str0[8], str))
            {
                sum += a*1.7;
                sum2 += a;
            }

            else if (!strcmp(str0[9], str))
            {
                sum += a*1.3;
                sum2 += a;
            }

            else if (!strcmp(str0[10], str))
            {
                sum += a*1.0;
                sum2 += a;
            }
            else if(!strcmp(str0[11],str))
                sum2 += a;




        }
        //cout << sum << endl;
        //cout << sum2 << endl;
        if (!sum2)
            puts("0.00");
        else
        printf("%.2lf\n", sum / sum2);
    }
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值