HDU4802_GPA
水题。
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
double totsum,totnum,k;
char s[5];
int n;
double get()
{
if (s[0]=='A')
{
if (s[1]==0) return 4;
else return 3.7;
}
if (s[0]=='B')
{
if (s[1]==0) return 3;
else if (s[1]=='+') return 3.3;
else return 2.7;
}
if (s[0]=='C')
{
if (s[1]==0) return 2;
else if (s[1]=='+') return 2.3;
else return 1.7;
}
if (s[0]=='D')
{
if (s[1]==0) return 1.3;
else return 1;
}
if (s[0]=='F') return 0;
return -1;
}
int main()
{
while (scanf("%d",&n)!=EOF)
{
totsum=totnum=0;
while (n--)
{
scanf("%lf%s",&k,s);
double tep=get(); //cout<<" this is : "<<tep<<endl;
if (tep<0) continue;
totnum+=k;
totsum+=k*tep;
}
if (totnum==0) printf("0.00\n");
else printf("%.2f\n",totsum/totnum);
}
return 0;
}
如有转载,请注明出处(http://www.cnblogs.com/lochan)