题解 | #成绩排序#
成绩排序
https://www.nowcoder.com/practice/3f27a0a5a59643a8abf0140b9a8cf1f7
#include <stdio.h> struct Student{ int num; int score; }stu[101]; int main() { int n,j=0; struct Student t; scanf("%d",&n); for(int i=0;i<n;i++){ scanf("%d %d",&stu[i].num,&stu[i].score); } for(int i=1;i<n;i++){ j=0; t=stu[i]; while(stu[i].score>stu[j].score){ j++; } for(int k=i;k>j;k--){ stu[k]=stu[k-1]; } stu[j]=t; } for(int i=0;i<n;i++){ printf("%d %d\n",stu[i].num,stu[i].score); } }