From 42766de5b83ad1c514b67107d11af3c88e29f0c1 Mon Sep 17 00:00:00 2001 From: psc2uwxgy Date: Fri, 22 Nov 2024 13:22:46 +0800 Subject: [PATCH] ADD file via upload --- 5th.c | 107 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 107 insertions(+) create mode 100644 5th.c diff --git a/5th.c b/5th.c new file mode 100644 index 0000000..35868f9 --- /dev/null +++ b/5th.c @@ -0,0 +1,107 @@ +#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]; + int i; + for ( i = 0; i < MAX_STUDENTS; i++) { + sum[i] = atof(data[i][3]) + atof(data[i][4]) + atof(data[i][5]); + } + int i1; + for (i1 = 0; i1 < MAX_STUDENTS - 1; i1++) { + int j; + for (j = 0; j < MAX_STUDENTS - 1 - i1; j++) { + if (atoi(data[j][1]) > atoi(data[j + 1][1])) { + int k; + for ( 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]) { + int k1; + for (k1 = 0; k1 < 6; k1++) { + char temp[MAX_LENGTH]; + strcpy(temp, data[j][k1]); + strcpy(data[j][k1], data[j + 1][k1]); + strcpy(data[j + 1][k1], 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'; + int i2; + for ( i2 = 0; i2 < MAX_STUDENTS; i2++) { + if (strcmp(data[i2][2], deletinfo) == 0) { + note = i; + break; + } + } + if (note == -1) { + int i3; + for ( i3 = 0; i3 < MAX_STUDENTS; i3++) { + if (strcmp(data[i3][0], deletinfo) == 0) { + note = i; + break; + } + } + } + + if (note!= -1) { + printf("Are you sure(yes/no)?"); + char con; + scanf(" %c", &con); + if (con == 'y') { + int a,b; + for (a = note; a < MAX_STUDENTS - 1; a++) { + for ( b = 0; b < 6; b++) { + strcpy(data[a][b], data[a + 1][b]); + } + } + int i4,j1; + for (i4 = 0; i4 < MAX_STUDENTS - 1; i4++) { + for ( j1 = 0; j1 < 6; j1++) { + printf("%s ", data[i4][j1]); + } + printf("\n"); + } + } else if (con == 'n') { + int i5,j2; + for ( i5 = 0; i5 < MAX_STUDENTS; i5++) { + for ( j2 = 0; j2 < 6; j2++) { + printf("%s ", data[i5][j2]); + } + printf("\n"); + } + } + } else { + int i6,j3; + for ( i6 = 0; i6 < MAX_STUDENTS; i6++) { + for (j3 = 0; j3 < 6; j3++) { + printf("%s ", data[i6][j3]); + } + printf("\n"); + } + } + + return 0; +}