HDU 1202(水题)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1202
直接贴代码:
1 #include <cstdio> 2 using namespace std; 3 4 int credit(double p) 5 { 6 if(p >= 90) 7 { 8 return 4; 9 } 10 else if(p >= 80) 11 { 12 return 3; 13 } 14 else if(p >= 70) 15 { 16 return 2; 17 } 18 else if(p >= 60) 19 { 20 return 1; 21 } 22 else 23 { 24 return 0; 25 } 26 } 27 28 int main() 29 { 30 int n; 31 double s, p; 32 double sum_s, sum_p; 33 while(scanf("%d", &n) != EOF) 34 { 35 sum_s = 0; 36 sum_p = 0; 37 for(int i = 0; i < n; i++) 38 { 39 scanf("%lf%lf", &s, &p); 40 if(p == -1) 41 { 42 continue; 43 } 44 sum_s += s; 45 sum_p += s * credit(p); 46 } 47 if(sum_s == 0) 48 { 49 printf("-1\n"); 50 } 51 else 52 { 53 printf("%.2lf\n", sum_p / sum_s); 54 } 55 } 56 return 0; 57 }