文章
18
粉丝
0
获赞
3
访问
10.8k
#include<stdio.h>
#include<stdlib.h>
typedef struct {
char name[50];
int score;
}number;
void BubbleSortDown(number* array, int length)
{
for (int i = length - 1; i > 0; i--) {
for (int j = 0; j < i; j++) {
if (array[i].score > array[j].score) {
number k = array[j];
array[j] = array[i];
array[i] = k;
}
}
}
}
void BubbleSortUp(number* array, int length)
{
for (int i = length-1; i>0; i--) {
for (int j = 0; j < i; j++) {
if (array[i].score < array[j].score) {
number k = array[j];
array[j] = array[i];
array[i] = k;
}
}
}
}
void print(number* array, int length) {
for (int i = 0; i < length; i++)
printf("%s %d\n", array[i].name, array[i].score);
}
int main() {
int n, k;
while (scanf("%d", &n) != EOF) {
scanf("%d", &k);
number* list = (number*)malloc(sizeof(number) * n);
for (int i = 0; i < n; i++) {
scanf("%s %d", list[i].name, &a...
登录后发布评论
相同成绩都按先录入排列在前的规则处理。