GPATime Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 2405 Accepted Submission(s): 1457
Problem Description
In college, a student may take several courses. for each course i, he earns a certain credit (c
i), and a mark ranging from A to F, which is comparable to a score (s
i), according to the following conversion table
![]() 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”.
Input
There are several test cases, please process till EOF.
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.
Output
For each test case, print the GPA (rounded to two decimal places) as the answer.
Sample Input
Sample Output
|
题意:按照公式统计GPA,注意忽略那些评分为P或N的课程。当总学分为0时输出0。
AC代码:
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <map>
#include <vector>
#define INF 0x3f3f3f3f
#define eps 1e-8
#define MAXN (100000+10)
#define MAXM (50000000)
#define Ri(a) scanf("%d", &a)
#define Rl(a) scanf("%lld", &a)
#define Rf(a) scanf("%lf", &a)
#define Rs(a) scanf("%s", a)
#define Pi(a) printf("%d\n", (a))
#define Pf(a) printf("%lf\n", (a))
#define Pl(a) printf("%lld\n", (a))
#define Ps(a) printf("%s\n", (a))
#define W(a) while(a--)
#define CLR(a, b) memset(a, (b), sizeof(a))
#define MOD 1000000007
#define LL long long
#define lson o<<1, l, mid
#define rson o<<1|1, mid+1, r
#define ll o<<1
#define rr o<<1|1
using namespace std;
double getscore(char *op)
{
if(op[0] == 'A')
{
if(op[1] == '-')
return 3.7;
else
return 4.0;
}
if(op[0] == 'B')
{
if(op[1] == '+')
return 3.3;
else if(op[1] == '-')
return 2.7;
else
return 3.0;
}
if(op[0] == 'C')
{
if(op[1] == '+')
return 2.3;
else if(op[1] == '-')
return 1.7;
else
return 2.0;
}
if(op[0] == 'D')
{
if(op[1] == '-')
return 1.0;
else
return 1.3;
}
return 0;
}
int main()
{
int n;
while(Ri(n) != EOF)
{
double ans = 0;
double Credit = 0;
for(int i = 0; i < n; i++)
{
double a; char str[4];
Rf(a); Rs(str);
if(str[0] != 'N' && str[0] != 'P')
{
ans += a * getscore(str);
Credit += a;
}
}
if(Credit == 0)
printf("0.00\n");
else
printf("%.2lf\n", ans / Credit);
}
return 0;
}