题解 | #学分绩点#

学分绩点

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

/*
实际成绩 绩点 
90——100 4.0 
85——89 3.7 
82——84 3.3 
78——81 3.0 
75——77 2.7 
72——74 2.3 
68——71 2.0 
64——67 1.5   
60——63 1.0 
60以下 0 
1.一门课程的学分绩点=该课绩点*该课学分 
2.总评绩点=所有学科绩点之和/所有课程学分之和 
现要求你编写程序求出某人A的总评绩点(GPA)。
*/



#include <stdio.h>
#include <stdlib.h>
int binSearch(int A[],int x){

    int low=0,high=9,mid;
    while(low<=high){
        mid = (low+high)/2;
        if(A[mid]==x)  return mid;
        else if(A[mid]<x) low = mid+1;
        else high = mid-1;
    }
    return low-1;
}

int main() {
    int match[10]={0,60,64,68,72,75,78,82,85,90};
    float gpa[10]={0,1,1.5,2.0,2.3,2.7,3.0,3.3,3.7,4.0};
    int n;
    while(scanf("%d",&n)==1){
        int total_study_point = 0;
        float total_gpa = 0;
        int *list=(int *)malloc(sizeof(int)*n);
        for(int i = 0;i<n;i++){
            int temp;
            scanf("%d",&temp);
            total_study_point+=temp;
            list[i]=temp;
        };
        
        for(int i = 0;i<n;i++){
            int temp;
            scanf("%d",&temp);
            total_gpa+=gpa[binSearch(match,temp)]*list[i];
        };
        printf("%.2f\n", total_gpa / total_study_point);
    }
	return 0;
}

全部评论

相关推荐

10-20 15:26
门头沟学院 Java
桥头牛油火锅:这个比例不正常,简历的话项目经历放中间,项目功能分点可以再明确点,前面加“·”或者“1 2 3”,另外简历上的照片可以去外面摄影店拍一下,以后也会用到的,hr筛人也是多少会看的,毕竟世界是一个巨大的卡颜局嘛,还有有些hr由于消息太多可能没看到,后面可能会回来找你,要简历的还会多一点,我也是普2本,比例大致是600:90:15:3,当然我实力不太够,拿的offer比较少,慢慢来吧
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务