修练者
题目链接: 酷町堂:9432
#include <stdio.h>
#include <string.h>
#define m 100//定义m最大值 宏定义
typedef struct {
char name[20];
int strawberry;
int cherry;
int mulberry;
int total;
} Student;
void so(Student students[100000], int n) {
for (int i = 0; i < n-1; i++) {
for (int j = 0; j < n-i-1; j++) {
if (students[j].total < students[j+1].total) {
Student temp = students[j];
students[j] = students[j+1];
students[j+1] = temp;
}
}
}
}
int main() {
int n;
scanf("%d", &n);
Student students[m];
for (int i = 0; i < n; i++)
{
scanf("%s %d %d %d", students[i].name, &students[i].strawberry, &students[i].cherry, &students[i].mulberry);
students[i].total = students[i].strawberry + students[i].cherry + students[i].mulberry;
}
so(students, n);
for (int i = 0; i < n; i++)
{
printf("%s %d\n", students[i].name, students[i].total);
}
return 0;
}
我到底哪里错了?