题解 | #学分绩点#
学分绩点
https://www.nowcoder.com/practice/a0c09a7e0da04e728810a8aca7226b7b
#include <stdio.h> //成绩对应学分 float getGPA(int x){ if (x>=90) return 4.0; else if(x >= 85) return 3.7; else if(x >= 82) return 3.3; else if(x >= 78) return 3.0; else if(x >= 75) return 2.7; else if(x >= 72) return 2.3; else if(x >= 68) return 2.0; else if(x >= 64) return 1.5; else if(x >= 60) return 1.0; else return 0; } int main(){ //输入 int num; scanf("%d", &num); int score[num]; for (int i = 0; i < num; ++i) { scanf("%d", &score[i]); } int grade[num]; for (int i = 0; i < num; ++i) { scanf("%d", &grade[i]); } //计算 float mark = 0; int sumScore = 0; for (int i = 0; i < num; ++i) { mark += score[i] * getGPA(grade[i]); sumScore += score[i]; } float GPA = mark / sumScore; printf("%.2f\n",GPA); return 0; }