You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

62 lines
2.2 KiB

#include <stdio.h>
struct student {
int xuehao;
int banji;
float gs;
float dy;
float dw;
float zcj;
char a[10];
};
int main() {
struct student b[4] = {10001, 11, 99.5, 88.5, 89.5, 0, " ",
10002, 12, 77.9, 56.5, 87.5, 0, " ",
10003, 11, 92.5, 99.0, 60.5, 0, " ",
0, 0, 0, 0, 0, 0, "inserted",
};
scanf("%d", &b[3].xuehao);
scanf("%d", &b[3].banji);
scanf("%f", &b[3].gs);
scanf("%f", &b[3].dy);
scanf("%f", &b[3].dw);
if (b[3].xuehao == b[0].xuehao)
printf("%d %d %.1f %.1f %.1f ", b[0].xuehao, b[0].banji, b[0].gs, b[0].dy, b[0].dw);
else if (b[3].xuehao == b[1].xuehao)
printf("%d %d %.1f %.1f %.1f ", b[1].xuehao, b[1].banji, b[1].gs, b[1].dy, b[1].dw);
else if (b[3].xuehao == b[2].xuehao)
printf("%d %d %.1f %.1f %.1f ", b[2].xuehao, b[2].banji, b[2].gs, b[2].dy, b[2].dw);
else {
for (int i = 0; i < 4; i++) { //计算总成绩
b[i].zcj = b[i].gs + b[i].dy + b[i].dw;
}
for (int i = 0; i < 3; i++) { //按总成绩排
for (int j = i + 1; j < 4; j++) {
struct student temp;
if (b[i].zcj < b[j].zcj) {
temp = b[i];
b[i] = b[j];
b[j] = temp;
}
}
}
int k = 1;
for (int i = 1; k <= 4; i++) {
for (int j = 0; j < 4; j++) {
if (b[j].banji == i) {
printf("%d %d %.1f %.1f %.1f ", b[j].xuehao, b[j].banji, b[j].gs, b[j].dy, b[j].dw);
printf("%s", b[j].a);
printf("\n");
k++;
}
}
}
}
return 0;
}