Time Limit: 1000 ms Case Time Limit: 1000 ms Memory Limit: 128 MB
Total Submission: 72 Submission Accepted: 32
Description
上学期面对繁重的课程和考试,TYF终于考完了。成绩出来之后,TYF想看一下GPA(Grade Point Average,平均成绩点数)是多少,之后他熟练的打开了教务处,看到绩点显示0.00,他丝毫没有感到吃惊,他知道教务处又出现问题了。之后TYF决定自己写一个程序来计算自己的GPA。想必大家都知道GPA如何计算的,就是加权平均数。计算方式如下:
例如某学生的五门课程的学分和他所获得的绩点为:
A课程四个学分,绩点4;
B课程三个学分,绩点3;
C课程两个学分,绩点4;
D课程六个学分,绩点2;
E课程三个学分,绩点3。
以上五项成绩GPA为:
GPA=(4*4+3*3+2*4+6*2+3*3)/(4+3+2+6+3)=3.00
现在让你帮助TYF完成这项任务。
Input
多组输入,EOF结束
对于每组输入,第一行一个整数n (1<=n<=40),表示课程的数目。
接下来n行,每行两个数,一个整数ai(1<=ai<=10)表示一门课的学分,一个浮点数bi(0<=bi<=4.00),表示一门课的绩点。
Output
对于每组输入,输出一行, 为平均成绩点数(保留两位小数)。
Sample Input
5
4 4.0
3 3.0
2 4.0
6 2.0
3 3.0
Sample Output
按照公式计算即可
1 /*
2 By:OhYee
3 Github:OhYee
4 Email:oyohyee@oyohyee.com
5 */
6 #include <cstdio>
7 #include <algorithm>
8 #include <cstring>
9 #include <cmath>
10 #include <string>
11 #include <iostream>
12 #include <vector>
13 #include <list>
14 #include <stack>
15 using namespace std;
16
17 #define REP(n) for(int o=0;o<n;o++)
18
19 int main() {
20 int n;
21 while(scanf("%d",&n) != EOF) {
22 double ans1 = 0,ans2 = 0;
23 double a,b;
24 REP(n) {
25 scanf("%lf%lf",&a,&b);
26 ans1 += a*b;
27 ans2 += a;
28 }
29 printf("%.2f
",ans2 != 0 ? ans1 / ans2 : 0);
30 }
31 return 0;
32 }