Title: http://vjudge.net/problem/HDU-1202
Analysis: This problem good pit father Ah, 80-89 4 points, let a person can't help set into 80<=i<=89, then 89.5 calculate not? There is also the need to consider all the missing test, division should have meaning.
1#include <cstdio>2#include <cstring>3#include <cmath>4#include <iostream>5#include <algorithm>6#include <string>7#include <cstdlib>8 9 using namespacestd;Ten One intMain () A { - intn,i; - Doubles[10010],p[10010],sum_s,sum_p; the while(~SCANF ("%d",&N)) - { -sum_s=0, sum_p=0; - for(i=1; i<=n;i++) + { -scanf"%LF%LF",&s[i],&p[i]); + if(p[i]==-1)Continue; A Else at { - if( -<=p[i]) p[i]=4; - Else if( the<=p[i]) p[i]=3; - Else if( -<=p[i]) p[i]=2; - Else if( -<=p[i]) p[i]=1; - Else if(0<=p[i]) p[i]=0; insum_s+=s[i],sum_p+=s[i]*P[i]; - } to } + if(sum_s) printf ("%.2lf\n",1.0*sum_p/sum_s); - Elseprintf"-1\n"); the } * return 0; $}
(HDU) 1202-The calculation of GPA (calculate GPA)