题解 | #学分绩点#
学分绩点
https://www.nowcoder.com/practice/a0c09a7e0da04e728810a8aca7226b7b
#include<iostream> using namespace std; const int N = 1010; int xuefen[N]; double jidian(double score) { double res = 0; if (score >= 90 && score <= 100) res = 4.0; else if (score >= 85 && score <= 89) res = 3.7; else if (score >= 82 && score <= 84) res = 3.3; else if (score >= 78 && score <= 81) res = 3.0; else if (score >= 75 && score <= 77) res = 2.7; else if (score >= 72 && score <= 74) res = 2.3; else if (score >= 68 && score <= 71) res = 2.0; else if (score >= 64 && score <= 67) res = 1.5; else if (score >= 60 && score <= 63) res = 1.0; else if (score < 60) res = 0; return res; } int main(void) { int n; cin >> n; int sum = 0; //学分之和 double xuefen_score = 0; for (int i = 0; i < n; i++) { cin >> xuefen[i]; sum += xuefen[i]; } for (int i = 0; i < n; i++) { int score; cin >> score; xuefen_score += jidian(score) * xuefen[i]; } double GPA = xuefen_score / sum; printf("%.2f\n", GPA); return 0; }