50175. Grading

難度:2/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
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "grading.h"

// typedef struct Submission {
// int subID;
// int studentID;
// char outputs[10][maxL];
// }Submission;

#define max(a,b) ((a)>(b)?(a):(b))

int cmp(const void* aa, const void* bb){
Submission* a = (Submission*)aa;
Submission* b = (Submission*)bb;
if(a->studentID != b->studentID){
return (a->studentID > b->studentID) ? 1 : -1;
}
else{
return (a->subID > b->subID) ? 1 : -1;
}
}

int get_grade(Submission *s, char answer[10][maxL]){
int cnt = 0;
for(int i = 0; i < 10; i++){
if(strcmp(s->outputs[i], answer[i]) == 0){
cnt += 10;
}
}
return cnt;
}

void grading(char answer[10][maxL], Submission* sub, int n){
qsort(sub, n, sizeof(Submission), cmp);
int max_grade = -1;
for(int i = 0; i < n; i++){
int now_grade = get_grade(&sub[i], answer);
printf("Student %d gets %d with Submission %d.\n",
sub[i].studentID, now_grade, sub[i].subID);
max_grade = max(max_grade, now_grade);
if(i == n - 1 || sub[i + 1].studentID != sub[i].studentID){
printf("Student %d gets %d in this exam.\n", sub[i].studentID, max_grade);
max_grade = -1;
}
}
}


50175. Grading
https://aaronlin1229.github.io/judgegirl_50175/
Author
Akizumi
Posted on
July 17, 2023
Licensed under