5 2 B 3 D- 2 P 1 F 3 A 2 2 P 2 N 6 4 A 3 A 3 A 4 A 3 A 3 A
2.33 0.00 4.00
Hint
For the first test case: GPA =(3.0 * 2 + 1.0 * 3 + 0.0 * 1 + 4.0 * 3)/(2 + 3 + 1 + 3) = 2.33 For the second test case: because credit in GPA computation is 0(P/N in additional treatment), so his/her GPA is “0.00”
一遍过的。。简单题,。
#include <stdio.h> #include <string.h> int main() { int n; while(scanf("%d",&n)!=EOF) { double a[1005]; char b[3005][10]; int i; memset(a,0,sizeof(a)); for(i=1;i<=n;i++) scanf("%lf%s",&a[i],b[i]); double sum=0; double sum1=0; for(i=1;i<=n;i++) { if(strcmp(b[i],"A")==0) { sum+=a[i]*4.0; sum1+=a[i]; } if(strcmp(b[i],"A-")==0) { sum+=a[i]*3.7;sum1+=a[i]; } if(strcmp(b[i],"B+")==0) { sum+=a[i]*3.3;sum1+=a[i]; } if(strcmp(b[i],"B")==0) { sum+=a[i]*3.0;sum1+=a[i]; } if(strcmp(b[i],"B-")==0) { sum+=a[i]*2.7;sum1+=a[i]; } if(strcmp(b[i],"C+")==0) { sum+=a[i]*2.3;sum1+=a[i]; } if(strcmp(b[i],"C")==0) { sum+=a[i]*2.0;sum1+=a[i]; } if(strcmp(b[i],"C-")==0) { sum+=a[i]*1.7;sum1+=a[i]; } if(strcmp(b[i],"D")==0) { sum+=a[i]*1.3;sum1+=a[i]; } if(strcmp(b[i],"D-")==0) { sum+=a[i]*1.0;sum1+=a[i]; } if(strcmp(b[i],"F")==0) { sum+=0;sum1+=a[i]; } } if(sum1) printf("%.2lf\n",sum/sum1); else printf("0.00\n"); } return 0; }
怒贴。。
原文地址:http://blog.csdn.net/sky_miange/article/details/42168949