The GPA is the weighted average score of all courses one student may take, if we treat the credit as the weight. In other words,
An additional treatment is taken for special cases. Some courses are based on “Pass/Not pass” policy, where stude nts earn a mark “P” for “Pass” and a mark “N” for “Not pass”. Such courses are not supposed to be considered in computation. These special courses must be ignored for computing the correct GPA.
Specially, if a student’s credit in GPA computation is 0, his/her GPA will be “0.00”.
Each test case starts with a line containing one integer N (1 <= N <= 1000), the number of courses. Then follows N lines, each consisting the credit and the mark of one course. Credit is a positive integer and less than 10.
求績點,公式如上圖。
思路:
水題。
//
// main.cpp
// A
//
// Created by zc on 2017/9/9.
// Copyright © 2017年 zc. All rights reserved.
//
#include <iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#define ll long long
using namespace std;
int n;
int main(int argc, const char * argv[]) {
while(~scanf("%d",&n))
{
double sum=0;
double ans=0;
for(int i=0;i<n;i++)
{
double t,p;
char c[2];
scanf("%lf%s",&t,c);
if(c[0]=='N'||c[0]=='P')continue;
if(c[0]=='A')
{
if(c[1]=='-') p=3.7;
else p=4.0;
}
if(c[0]=='B')
{
if(c[1]=='+') p=3.3;
else if(c[1]=='-') p=2.7;
else p=3.0;
}
if(c[0]=='C')
{
if(c[1]=='+') p=2.3;
else if(c[1]=='-') p=1.7;
else p=2.0;
}
if(c[0]=='D')
{
if(c[1]=='-') p=1.0;
else p=1.3;
}
if(c[0]=='F') p=0.0;
ans+=t*p;
sum+=t;
}
if(sum==0) ans=0;
else ans/=sum;
printf("%.2f\n",ans);
}
}