hdu_1202 The calculation of GPA

http://acm.hdu.edu.cn/showproblem.php?pid=1202


分析: 果然最近一直在刷水題



代碼:

//hdu 1202
#include <iostream>
#include <stdio.h>
using namespace std;

int main()
{
    int n;
    double s,p;
    double sums,sumj;
    while(scanf("%d",&n)!=EOF){
        sums=0,sumj=0;
        for(int i=0;i<n;i++){
            scanf("%lf%lf",&s,&p);
            if(p == -1) continue;
            sums +=s;
            p = (p-50)/10;
            if(p==5.0) p--;
            if(p<0)    p=0;
            sumj += (s* int(p));
        }
        if(sums==0) printf("-1\n");
        else        printf("%.2f\n",sumj/sums);
    }
    return 0;
}


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章