(HDU)1202 -- The calculation of GPA (计算GPA)

题目:http://vjudge.net/problem/HDU-1202

分析:这题好坑爹啊,80 - 89 4点,让人情不自禁设置成80<=i<=89,那么89.5算不算呢?还有就是全部缺考的情况也需要考虑,除法要有意义。

 1 #include <cstdio>
 2 #include <cstring>
 3 #include <cmath>
 4 #include <iostream>
 5 #include <algorithm>
 6 #include <string>
 7 #include <cstdlib>
 8 
 9 using namespace std;
10 
11 int main()
12 {
13     int n,i;
14     double s[10010],p[10010],sum_s,sum_p;
15     while(~scanf("%d",&n))
16     {
17         sum_s=0,sum_p=0;
18         for(i=1;i<=n;i++)
19         {
20             scanf("%lf %lf",&s[i],&p[i]);
21             if (p[i]==-1) continue;
22             else
23             {
24                 if(90<=p[i]) p[i]=4;
25                 else if(80<=p[i]) p[i]=3;
26                 else if(70<=p[i]) p[i]=2;
27                 else if(60<=p[i]) p[i]=1;
28                 else if(0<=p[i]) p[i]=0;
29                 sum_s+=s[i],sum_p+=s[i]*p[i];
30             }
31         }
32         if(sum_s) printf("%.2lf\n",1.0*sum_p/sum_s);
33         else printf("-1\n");
34     }
35     return 0;
36 }

 

posted @ 2016-12-05 12:00  ACDoge  阅读(333)  评论(0编辑  收藏  举报