码迷,mamicode.com
首页 > 其他好文 > 详细

hdu 1202 The calculation of GPA

时间:2016-07-20 21:25:06      阅读:162      评论:0      收藏:0      [点我收藏+]

标签:

技术分享

 

#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");
    }
}

  

hdu 1202 The calculation of GPA

标签:

原文地址:http://www.cnblogs.com/A--Q/p/5689624.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!