Description


Input
Output
Sample Input
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
Sample Output
2.33 0.00 4.00
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <map>
using namespace std;
map<string, double> mp;
int n;
int main() {
int m;
string str;
mp["A"] = 4.0, mp["A-"] = 3.7, mp["B+"] = 3.3;
mp["B"] = 3.0, mp["B-"] = 2.7, mp["C+"] = 2.3;
mp["C"] = 2.0, mp["C-"] = 1.7, mp["D"] = 1.3;
mp["D-"] = 1.0, mp["F"] = 0.0;
while (scanf("%d", &n) != EOF) {
double ans = 0.00;
int sum = 0;
for (int i = 0; i < n; i++) {
cin >> m >> str;
if (str == "P" || str == "N")
continue;
sum += m;
ans += (double) m * mp[str];
}
if (sum == 0)
printf("0.00\n");
else printf("%.2f\n", 1.0*ans/sum);
}
return 0;
}
原文:http://blog.csdn.net/u011345136/article/details/40323775