sort
#include<bits/stdc++.h>
using namespace std;
bool cmp(int a,int b)
{
return a > b;
}
int main()
{
int n,a[205],i;
cin >> n;
for(i=0;i<n;i++)
{
cin >> a[i];
}
sort (a,a+n,cmp);
for(i=0;i<n-1;i++)
{
cout << a[i] << " ";
}
cout << a[n-1] << endl;
return 0;
}
#include<bits/stdc++.h>
using namespace std;
struct Student
{
string name;
int score;
}student[100];
bool cmp(Student s1, Student s2)
{
return s1.score > s2.score;
}
int main()
{
int n,i,j;
cin >> n;
for(i=0;i<n;i++)
{
cin >> student[i].name >> student[i].score;
}
sort(student,student+n,cmp);
for(j = 0;j < n; j++)
{
cout << student[j].name << " " << student[j].score << endl;
}
return 0;
}
#include<bits/stdc++.h>
using namespace std;
struct Student
{
string name;
int sum;
int chinese;
int math;
int english;
}student[205];
bool cmp(Student a,Student b)
{
if(a.sum==b.sum)
{
if(a.chinese==b.chinese)
{
return a.math > b.math;
}
else return a.chinese > b.chinese;
}
else return a.sum >b.sum;
}
int main(int argc, char** argv)
{
int n,i;
cin >> n;
for(i=0;i<n;i++)
{
cin >> student[i].name >>student[i].sum >> student[i].chinese >> student[i].math >> student[i].english;
}
sort(student,student+n,cmp);
for(i=0;i<n;i++)
{
cout << student[i].name << " " << student[i].sum << " " << student[i].chinese << " " << student[i].math << " " << student[i].english << endl;
}
return 0;
}