From ea57434da082a4d259e4ecec6c6b54587ff309d0 Mon Sep 17 00:00:00 2001 From: pvkyt5ngb Date: Fri, 10 Nov 2023 12:00:10 +0800 Subject: [PATCH] =?UTF-8?q?Add=20=E6=AD=A5=E9=AA=A4=E5=9B=9B.c?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 步骤四.c | 61 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 步骤四.c diff --git a/步骤四.c b/步骤四.c new file mode 100644 index 0000000..06a1204 --- /dev/null +++ b/步骤四.c @@ -0,0 +1,61 @@ +#include + +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; +}