ADD file via upload

main
psc2uwxgy 23 hours ago
parent 5315f027b2
commit 42766de5b8

107
5th.c

@ -0,0 +1,107 @@
#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];
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;
}
Loading…
Cancel
Save