题解 | #学分绩点#
学分绩点
https://www.nowcoder.com/practice/a0c09a7e0da04e728810a8aca7226b7b
#include<cstdio> #include<vector> using namespace std; double run(int n){ if (n >= 90){ return 4.0; } else if (n >= 85 && n <= 89){ return 3.7; } else if (n >= 82 && n <= 84){ return 3.3; } else if (n >= 78 && n <= 81){ return 3.0; } else if (n >= 75 && n <= 77){ return 2.7; } else if (n >= 72 && n <= 74){ return 2.3; } else if (n >= 68 && n <= 71){ return 2.0; } else if (n >= 64 && n <= 67){ return 1.5; } else if (n >= 60 && n <= 63){ return 1.0; } else { return 0; } } int main(){ int n; while (scanf("%d", &n) != EOF){ vector<int>vec1; vector<int>vec2; int sum = 0; for (int i = 0; i < n; i++){ int q; scanf("%d", &q); vec1.push_back(q); sum = sum + q; } for (int i = 0; i < n; i++){ int q; scanf("%d", &q); vec2.push_back(q); } float GPA=0; for (int i = 0; i < n; i++){ GPA = vec1[i] * run(vec2[i])+GPA; } GPA = GPA / sum; printf("%.2f", GPA); } }