文章
47
粉丝
109
获赞
8
访问
28.4k
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
struct Node {
int id;//学号
int score;//成绩
};
int main() {
int n;
scanf("%d", &n);
struct Node p[105];//初始化数组
for (int i = 0; i < n; i++) {
scanf("%d %d", &p[i].id, &p[i].score);
}
//冒泡排序具有稳定性
//先调整学号
for (int i = 0; i < n; i++) {
for (int j = 0; j < n - i - 1; j++) {
if (p[j].id > p[j + 1].id) {
int temp2 = p[j].id;
int temp1 = p[j].score;
p[j].id = p[j + 1].id;
p[j].score = p[j + 1].score;
p[j + 1].id = temp2;
p[j + 1].score = temp1;
}
}
}
//再调整成绩
for (int i = 0; i < n; i++) {
for (int j = 0; j < n - i - 1; j++) {
if (p[j].score > p[j + 1].score) {
int temp2 = p[j].id;
int temp1 = p[j].score;
p[j].id = p[j + 1].id;
p[j].score = p[j + 1].score;
p[j + 1].id = temp2;
p[j + 1].score = temp1;
}
}
}
for (int i = 0; i < n; i++) {
prin...
登录后发布评论
暂无评论,来抢沙发