题解 | #成绩排序#
成绩排序
https://www.nowcoder.com/practice/3f27a0a5a59643a8abf0140b9a8cf1f7
#include<stdio.h> struct Student{ int number; int score; }; int main(){ int n; struct Student arr[100]; while(scanf("%d", &n) != EOF){ for(int i = 0; i < n; i++){ scanf("%d %d",&arr[i].number, &arr[i].score); } for(int i = 0; i < n; i++){ for(int j = i+1; j < n; j++){ if(arr[i].score > arr[j].score){ int v = arr[i].score; int n = arr[i].number; arr[i].score = arr[j].score; arr[i].number = arr[j].number; arr[j].score = v; arr[j].number = n; } if(arr[i].score == arr[j].score){ if(arr[i].number > arr[j].number ){ int v = arr[i].number; arr[i].number = arr[j].number; arr[j].number = v; } } } } for(int i = 0; i < n; i++){ printf("%d %d\n",arr[i].number, arr[i].score); } } return 0; }