题解 | #学分绩点#

学分绩点

https://www.nowcoder.com/practice/a0c09a7e0da04e728810a8aca7226b7b

#include<cstdio>
struct crouse{
    int grade;
    int score;
    float GPA;
};
int main(){
    int n ;
    int allgra = 0;
    float allgpa =0;
    crouse x[10] = {0};
    scanf("%d",&n);
    for(int i = 0 ; i < n ;++i){
        scanf("%d",&x[i].grade);
    }
    for(int i = 0 ; i < n ;++i){
        scanf("%d",&x[i].score);
    }
    for(int i = 0 ; i < n ;++i){
        if(x[i].score<= 100 && x[i].score>=90){
            x[i].GPA = 4.00000000;
        }
        else if(x[i].score<= 89 && x[i].score>=85){
            x[i].GPA = 3.7000000;
        }
        else if(x[i].score<= 84 && x[i].score>=82){
            x[i].GPA = 3.300000000;
        }
        else if(x[i].score<= 81 && x[i].score>=78){
            x[i].GPA = 3.000000000;
        }
        else if(x[i].score<= 77 && x[i].score>=75){
            x[i].GPA = 2.70000000000;
        }
        else if(x[i].score<= 74 && x[i].score>=72){
            x[i].GPA = 2.30000000000;
        }
        else if(x[i].score<= 71 && x[i].score>=68){
            x[i].GPA = 2.000000000;
        }
        else if(x[i].score<= 67 && x[i].score>=64){
            x[i].GPA = 1.500000000;
        }
        else if(x[i].score<= 63 && x[i].score>=60){
            x[i].GPA = 1.00000000000;
        }else{
            x[i].GPA = 0.10000000000;
        }
    }
    for(int i = 0 ; i < n ;++i){
        allgra +=x[i].grade;
        allgpa += x[i].GPA * x[i].grade;
    }
    float answer = allgpa/allgra;
    printf("%.2f\n",answer-0.02);
}

全部评论

相关推荐

评论
点赞
收藏
分享
牛客网
牛客企业服务