hdu1202The calculation of GPA

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

继续水水水水水。

代码:
#include <cstdio>
#include <cstring>

struct Node
{
    double s;
    double p;
    double gp;
}a[1000000];

int main()

{
    int _;
    while(~scanf("%d",&_))
    {
        memset(a,0,sizeof(a));
        for(int i = 0;i < _;++i)
        {
            scanf("%lf%lf",&a[i].s,&a[i].p);
            if(a[i].p != -1)
            {
                if(a[i].p >= 90.0)
                    a[i].gp = 4 * a[i].s;
                else if(a[i].p >= 80.0)
                    a[i].gp = 3 * a[i].s;
                else if(a[i].p >= 70.0)
                    a[i].gp = 2 * a[i].s;
                else if(a[i].p >= 60.0)
                    a[i].gp = 1 * a[i].s;
            }
        }
        double sums = 0;
        double sump = 0;
        for(int i = 0; i < _;++i)
        {
            sums += a[i].s;
            if(a[i].p != -1)
            {
                sump += a[i].gp;
            }
        }
        if(sump)
            printf("%.2lf\n",sump / sums);
        else
            printf("-1\n");
    }
}

你可能感兴趣的:(ACM,水)