文章
4
粉丝
22
获赞
6
访问
491
通过索引让同分的输出按先后顺序排列
#include <bits/stdc++.h>
using namespace std;
struct Student {
string name;
int score;
int index; // 记录学生输入的顺序
};
// 降序
bool compareDe(const Student &a, const Student &b) {
if (a.score == b.score) {
return a.index < b.index; // 分数相同时,按输入顺序排序
}
return a.score > b.score;
}
// 升序
bool compareAs(const Student &a, const Student &b) {
if (a.score == b.score) {
return a.index < b.index; // 分数相同时,按输入顺序排序
}
return a.score < b.score;
}
int main() {
// num人数,method排序方法
int num, method;
while (cin >> num) {
if (num == 0)
break;
cin >> method;
// ...
登录后发布评论
暂无评论,来抢沙发