# 2849. 成绩排序

Python3 多条件排序

n = int(input())

for _ in range(n):



#include
using namespace std;

struct student {string num; int score;};
struct cmp {
bool operator() (const student &a, const student &b) {
if (a.score != b.score) return a.score < b.score;
else return a.num > b.num;
}
};
int main() {
//freopen("testin.txt", "r", stdin);
//freopen("testout.txt", "w", stdout);
int n;
student tmp;
priority_queue <student, vector<student>, cmp> p;
cin >> n;
for (int i=0; i<n; ++i) {
cin >> tmp.num >> tmp.score;
p.push(tmp);
}
while (!p.empty() && p.top().score >= 60) {
cout << p.top().num << ' ' << p.top().score << endl;
p.pop();
}
return 0;
}


### include

#include <string.h>
#include <stdlib.h>
typedef struct {char num[12]; int score;} stu;
int cmp (const void *a, const void *b) {
stu *x = (stu *)a;
stu *y = (stu *)b;
if (x->score != y->score) return y->score - x->score;
else return strcmp(x->num, y->num);
}
int main() {
//freopen("testin.txt", "r", stdin);
//freopen("testout.txt", "w", stdout);
int n, i;
stu a[101];
scanf("%d", &n);
for (i=0; i<n; ++i)
scanf("%s%d", a[i].num, &a[i].score);
qsort(a, n, sizeof(a[0]), cmp);
for (i=0; i<n; ++i) {
if (a[i].score < 60) break;
printf("%s %d\n", a[i].num, a[i].score);
}
return 0;
}


### include

using namespace std;

struct stu{
long long num;
int score;
};

bool cmp(stu a, stu b){
if(a.score == b.score){
return a.num < b.num; // 非降序
}
return a.score > b.score;// 非升序
}

int main()
{
int n;
cin >> n;
int i;
stu a[n];
for(i = 0; i < n; i++){
cin >> a[i].num >> a[i].score;
}
sort(a, a + n, cmp);
for(i = 0; i < n; i++){
if(a[i].score >= 60){
cout << a[i].num << ” ” << a[i].score << endl;
}
}
return 0;
}

### include

using namespace std;

int main()
{
int n;
cin >> n;
int i;
long long a[n][2];
for(i = 0; i < n; i++){
a[i][0] = num;
}
int j;
int flag = 0;
for(i = 0; i < n; i++){
flag = 0;
for(j = n - 1; j > i; j–){
if(a[j][1] > a[j-1][1]){
long long tmp_n, tmp_g;
tmp_n = a[j][0];
tmp_g = a[j][1];
a[j][0] = a[j-1][0];
a[j][1] = a[j-1][1];
a[j-1][0] = tmp_n;
a[j-1][1] = tmp_g;
}
if(a[j][1] == a[j-1][1]){
if(a[j][0] < a[j-1][0]){
long long tmp_n, tmp_g;
tmp_n = a[j][0];
tmp_g = a[j][1];
a[j][0] = a[j-1][0];
a[j][1] = a[j-1][1];
a[j-1][0] = tmp_n;
a[j-1][1] = tmp_g;
}
}
}
}
for(i = 0; i < n; i++){
if(a[i][1] >= 60){
cout << a[i][0] << ” ” << a[i][1] << endl;
}
}
return 0;
}

### include

using namespace std;
int n;
struct Stu
{
string SID;
int score;
bool operator<(const Stu& bb) const
{
if(score!=bb.score) return score>bb.score;
else return SID<bb.SID;
}
};
vector V;

int main()
{
cin>>n;
for(int i=1;i<=n;i++)
{
string x;int y;
cin>>x>>y;
if(y>=60) V.push_back((Stu){x,y});
}
sort(V.begin(),V.end());
for(int i=0;i<V.size();i++)
cout<<V[i].SID<<’ ‘<<V[i].score<<endl;
return 0;
}

### include

using namespace std;
int n;
struct Stu
{
string SID;
int score;
};
vector V;
int cmp(const Stu& aa,const Stu& bb)
{
if(aa.score!=bb.score) return aa.score>bb.score;
else return aa.SID>n;
for(int i=1;i<=n;i++)
{
string x;int y;
cin>>x>>y;
if(y>=60) V.push_back((Stu){x,y});
}
sort(V.begin(),V.end(),cmp);
for(int i=0;i<V.size();i++)
cout<<V[i].SID<<’ ‘<<V[i].score<<endl;
return 0;
}

0打头啊真的蠢。证据确凿，百口莫辩。

### include

typedef struct
{
char num[13];
int score;
}
stu;

int cmp (const void a, const void b) {
stu x = (stu )a;
stu y = (stu )b;
if(x->score == y->score)
{
return strcmp(x->num , y->num);
}
else return y->score - x->score;
}
int main()
{
int n,i;
stu a[101];
scanf(“%d”,&n);
for(i=0;i<n;i++)
{
scanf(“%s %d”,a[i].num,&a[i].score);
}

qsort(a,n,sizeof(a[0]),cmp);

for(i=0;i<n;i++)
{
if(a[i].score<60) continue;
printf("%s %d\n",a[i].num,a[i].score);

}
return 0;


}