Evaluate delta and select this course (unselected
The score is 0). The score + delta is used to calculate the average score of the course. The average score is equal to the average score of all the students selected for the course.
1 # include <stdio. h>
2 # include <stdlib. h>
3
4 // int count_in = 0;
5 // int deta = 0;
6
7 // (y1 + y2 +... y_count_in + (count_in) * detal)/count_in = n1 = sum/count_in
8 // y1 indicates the source score of the course,
9 // sum adds the average of all courses for each student (the course has already been selected) one by one, and the next count_in is the average of all the scores of all the students in the course.
10 // count_in indicates the number of students selected for this course
11 // n1 indicates the average value of all the scores of all the students in this course.
12 // detal is the difference value required for the current portal.
13 // => detal = (sum-(y1 + y2.... y_count_in)/count_in
14 // => detal = (sum-totalOfClass)/count_in.
15 int f_pinjun (int data [] [10], int student_num, int row, int class_num)
16 {
17 int count_in = 0;
18 int I, sum = 0, tmp_sum, j, n_stu_class_num, totalOfClass = 0;
19 // deta = 0;
20
21 for (I = 0; I <student_num; I ++)
22 {
23 if (data [I] [row]! = 0)
24 {
25 tmp_sum = 0;
26 n_stu_class_num = 0;
27 for (j = 0; j <class_num; j ++) // There are too many duplicates in this place ., The average value of each student should be saved in advance and then called to avoid repetition.
28 {
29 if (data [I] [j]! = 0)
30 {
31 n_stu_class_num ++;
32 tmp_sum + = data [I] [j];
33}
34
35}
36
37 totalOfClass + = data [I] [row];
38 tmp_sum/= n_stu_class_num;
39 count_in ++;
40 sum + = tmp_sum; // sum the average of all courses for each student (this course has already been selected, in the following example, count_in is the average value of all the scores of all the students who have chosen this course.
41}
42}
43 // deta = totalOfClass/count_in;
44 // return sum/count_in;
45 return (sum-totalOfClass)/count_in;
46}
47
48 int main ()
49 {
50 char class_name [10] [15];
51 int student_num, class_num, I, data [20] [10], j;
52 // int pinjun [10] = {0, 0 };
53 scanf ("% d", & student_num, & class_num );
54 // printf ("% d \ n", student_num, class_num );
55
56 for (I = 0; I <class_num; I ++)
57 {
58 scanf ("% s", class_name [I]);
59}
60
61 for (I = 0; I <student_num; I ++)
62 {
63 for (j = 0; j <class_num; j ++)
64 scanf ("% d", & data [I] [j]);
65}
66
67 // print_data (data, student_num, class_num );
68
69 for (I = 0; I <class_num; I ++)
70 {
71 // pinjun [I] = f_pinjun (data, student_num, I, class_num );
72 // printf ("% d", pinjun [I]);
73 // if (I! = Class_num-1)
74 // printf ("% s % d \ n", class_name [I], pinjun [I]-deta );
75 // printf ("% d \ n", deta );
76 printf ("% s % d \ n", class_name [I], f_pinjun (data, student_num, I, class_num ));
77}
78 // printf ("% s % d", class_name [I-1], pinjun [I]-deta );
79
80 return 0;
81}
ACM 2 step-by-step implementation and implementation will improve it.
From zhengmian