hdu 1202 The calculation of GPA

 

感觉本题没有什么好解释的,已知公式,直接编程即可。

1.统计所有 科目的学分 得到总学分

2.统计所有 成绩对应的绩点*对应的学分即可(如果成绩==-1直接continue,不进行统计),得到总绩点。

3.如果总绩点<0 sorry -1,没有平均绩点

4. 总绩点/总学分 即可得到平均绩点 

 

#include <stdio.h>
int f(double x)
{
    if(x>=90)return 4;
    else if(x>=80)return 3;
    else if(x>=70)return 2;
    else if(x>=60)return 1;
    else return 0;
}

int main(void)
{
    int n;double cj,zjd,xf,zxf;
    while(scanf("%d",&n)!=EOF)
    {
        zxf=zjd=0;
        while(n--)
        {
            scanf("%lf%lf",&xf,&cj);
            if(cj==-1)continue;
            zxf+=xf;
            zjd+=xf*f(cj);
        }
        if(zjd>0)
            printf("%.2f\n",zjd/zxf);
        else
            printf("-1\n");
    }
}

  

posted @ 2016-07-20 20:29  马丁黄瓜啊  阅读(190)  评论(0编辑  收藏  举报