ADD file via upload

main
p3afi4g2n 1 week ago
parent 0d08cd46c2
commit b3e7a1ee4d

@ -0,0 +1,96 @@
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#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;
}
Loading…
Cancel
Save