题解 | #成绩排序#
成绩排序
https://www.nowcoder.com/practice/3f27a0a5a59643a8abf0140b9a8cf1f7
#include<algorithm>
#include<cstdio>
using namespace std;
typedef struct student{
int xuehao;
int score;
}student;
bool com(student left,student right)
{
if(left.score<right.score)
{
return true;
}
else if(left.score==right.score&&left.xuehao<=right.xuehao)
{
return true;
}
else
return false;
}
int main()
{
int n;
student s[101];
scanf("%d",&n);
for(int i=1;i<=n;i++)
{
scanf("%d %d",&s[i].xuehao,&s[i].score);
}
sort(s+1,s+n+1,com);
for(int i=1;i<=n;i++)
{
printf("%d %d",s[i].xuehao,s[i].score);
printf("\n");
}
}
好神奇,有点领悟其中怎么运算了,关键来说,还是要找对数据结构!!以及存储结构,这样才能决定其运算方式
上海得物信息集团有限公司公司福利 1182人发布
