50139. GPA

難度:2.5/5

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#include <stdio.h>
#include <stdlib.h>
#include "GPA_calculation.h"

// struct Class{
// int academic_credit;
// char score[3];
// };
// struct Student{
// char name[20];
// int N_class; // total number of classes the student takes.
// int N_credit; // total number of academic credits.
// double GPA;
// struct Class all_class[10];
// };

int cmp(const void* sa, const void* sb){
struct Student* a = (struct Student*)sa;
struct Student* b = (struct Student*)sb;

if(b->GPA > a->GPA) return 1;
else if(b->GPA == a->GPA) return 0;
else return -1;
}


static double mapping[10] = {(double)4.3, (double)4.0, (double)3.7,
(double)3.3, (double)3.0, (double)2.7,
(double)2.3, (double)2.0, (double)1.7, (double)0.0};

double get_gpa(char* score){
int p;
if(score[0] == 'A') p = 1;
else if(score[0] == 'B') p = 4;
else if(score[0] == 'C') p = 7;
else if(score[0] == 'F') p = 9;
if(score[1] == '+') p--;
else if(score[1] == '-') p++;
return mapping[p];
}

void get_cred_gpa(struct Student* s){
s->N_credit = 0;
double sum = (double)0.0;
for(int i = 0; i < s->N_class; i++){
s->N_credit += s->all_class[i].academic_credit;
sum += get_gpa(s->all_class[i].score) * (double)(s->all_class[i].academic_credit);
}
s->GPA = (double)sum / (double)(s->N_credit);
}

void GPA_calculation(struct Student stnd[], int n){
int num_awards = ((n - 1) / 20) + 1;
for(int i = 0; i < n; i++) get_cred_gpa(&stnd[i]);
qsort(stnd, n, sizeof(struct Student), cmp);

for(int i = 0; i < num_awards; i++){
struct Student* s = &stnd[i];
if(s->N_credit < 15 || s->GPA < (double)(3.38)) continue;
printf("%d %s %f\n", i + 1, s->name, s->GPA);
}

}


50139. GPA
https://aaronlin1229.github.io/judgegirl_50139/
Author
Akizumi
Posted on
July 17, 2023
Licensed under