题解 | #争夺前五名#
争夺前五名
https://www.nowcoder.com/practice/cd052308a1c44a88ad00255f312c3e14
#include <stdio.h> int main() { int n; scanf("%d",&n); int grade[n],temp; for(int i=0;i<n;i++) scanf("%d",&grade[i]); for(int i=0;i<5;i++) { for(int j=i;j<n;j++) { if(grade[i]<grade[j]) { temp=grade[i]; grade[i]=grade[j]; grade[j]=temp; } } } for(int i=0;i<5;i++) printf("%d ",grade[i]);//输出前五项 }