题解 | #成绩排序#
成绩排序
https://www.nowcoder.com/practice/3f27a0a5a59643a8abf0140b9a8cf1f7
#include <cstdio> #include <iostream> #include <algorithm> using namespace std; struct Student{ int number; int score; }; Student arr[100]; bool compare(Student x ,Student y){ if (x.score == y.score){ return x.number <y.number; } else{ return x.score < y.score; } } int main(){ int n; scanf("%d",&n); for (int i = 0;i<n;i++){ int p,q; scanf("%d %d ",&p,&q); arr[i].number=p; arr[i].score=q; } sort(arr,arr+n,compare); for (int i = 0;i<n;i++){ printf("%d %d\n",arr[i].number,arr[i].score); } return 0; }