#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