【思路】:模拟。
【注意】:题目要求的是实型。并且题目有没说清楚的地方,全部缺考和学分*点数为0这两种情况都算GPA不存在!
参考:http://blog.csdn.net/liuzhushiqiang/article/details/8603798
【AC代码】:
#include <iostream> #include <cstdlib> #include <cstdio> #include <cstring> #include <algorithm> #include <iomanip> using namespace std; #define MAX 100 struct Course { double s; double p; }; int main() { Course cour[MAX]; int n = 0; while (cin >> n) { int i = 0; double tp = 0, t = 0; for (i = 0; i < n; i++) cin >> cour[i].s >> cour[i].p; for (i = 0; i < n; i++) { if (cour[i].p >= 90) t += 4*cour[i].s; else if (cour[i].p >= 80) t += 3*cour[i].s; else if (cour[i].p >= 70) t += 2*cour[i].s; else if (cour[i].p >= 60) t += 1*cour[i].s; if (cour[i].p != -1) tp += cour[i].s; } if (t!=0 && tp!=0) cout << fixed << setprecision(2) << t/tp << endl; else cout << -1 << endl; } return 0; }
时间: 2024-10-12 17:29:53