From b3e7a1ee4d478821a1eff55310d207692f6df04e Mon Sep 17 00:00:00 2001 From: p3afi4g2n <2990918050@qq.com> Date: Fri, 22 Nov 2024 15:18:36 +0800 Subject: [PATCH] ADD file via upload --- step5.c | 96 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 96 insertions(+) create mode 100644 step5.c diff --git a/step5.c b/step5.c new file mode 100644 index 0000000..fc8d57d --- /dev/null +++ b/step5.c @@ -0,0 +1,96 @@ +#include +#include +#include + +#define MAX_STUDENTS 3 +#define MAX_LENGTH 40 + +int main() { + char data[MAX_STUDENTS][6][MAX_LENGTH] = {{"10001\0", "11\0", "Zhang\0", "99.5\0", "88.5\0", "89.5\0"}, + {"10002\0", "12\0", "Yang\0", "77.9\0", "56.5\0", "87.5\0"}, + {"10003\0", "11\0", "Liang\0", "92.5\0", "99.0\0", "60.5\0"}}; + double sum[MAX_STUDENTS]; + for (int i = 0; i < MAX_STUDENTS; i++) { + sum[i] = atof(data[i][3]) + atof(data[i][4]) + atof(data[i][5]); + } + for (int i = 0; i < MAX_STUDENTS - 1; i++) { + for (int j = 0; j < MAX_STUDENTS - 1 - i; j++) { + if (atoi(data[j][1]) > atoi(data[j + 1][1])) { + for (int k = 0; k < 6; k++) { + char temp[MAX_LENGTH]; + strcpy(temp, data[j][k]); + strcpy(data[j][k], data[j + 1][k]); + strcpy(data[j + 1][k], temp); + } + double tempSum = sum[j]; + sum[j] = sum[j + 1]; + sum[j + 1] = tempSum; + } else if (atoi(data[j][1]) == atoi(data[j + 1][1]) && sum[j] > sum[j + 1]) { + for (int k = 0; k < 6; k++) { + char temp[MAX_LENGTH]; + strcpy(temp, data[j][k]); + strcpy(data[j][k], data[j + 1][k]); + strcpy(data[j + 1][k], temp); + } + double tempSum = sum[j]; + sum[j] = sum[j + 1]; + sum[j + 1] = tempSum; + } + } + } + + char deletinfo[MAX_LENGTH]; + int note = -1; + int count = 0; + fgets(deletinfo, MAX_LENGTH, stdin); + deletinfo[strcspn(deletinfo, "\n")] = '\0'; + for (int i = 0; i < MAX_STUDENTS; i++) { + if (strcmp(data[i][2], deletinfo) == 0) { + note = i; + break; + } + } + if (note == -1) { + for (int i = 0; i < MAX_STUDENTS; i++) { + if (strcmp(data[i][0], deletinfo) == 0) { + note = i; + break; + } + } + } + + if (note!= -1) { + printf("Are you sure(yes/no)?"); + char con; + scanf(" %c", &con); + if (con == 'y') { + for (int a = note; a < MAX_STUDENTS - 1; a++) { + for (int b = 0; b < 6; b++) { + strcpy(data[a][b], data[a + 1][b]); + } + } + for (int i = 0; i < MAX_STUDENTS - 1; i++) { + for (int j = 0; j < 6; j++) { + printf("%s ", data[i][j]); + } + printf("\n"); + } + } else if (con == 'n') { + for (int i = 0; i < MAX_STUDENTS; i++) { + for (int j = 0; j < 6; j++) { + printf("%s ", data[i][j]); + } + printf("\n"); + } + } + } else { + for (int i = 0; i < MAX_STUDENTS; i++) { + for (int j = 0; j < 6; j++) { + printf("%s ", data[i][j]); + } + printf("\n"); + } + } + + return 0; +} \ No newline at end of file