问题标题: 酷町堂:9432助力果农为什么只有40分

0
0
已解决
梁辰晖
梁辰晖
修练者
修练者

题目链接: 酷町堂: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;

}

我到底哪里错了?


0
0
钱宏远
钱宏远
高级守护
高级守护

你们老师教了swap排序了吗?

0
我要回答