题解 | #争夺前五名#
争夺前五名
https://www.nowcoder.com/practice/cd052308a1c44a88ad00255f312c3e14
#include <stdio.h> #include<stdlib.h> int compare_int(const void* a, const void* b) { return *(int*)b - *(int*)a; } int main() { int arr[50] = { 0 }, n, i; scanf("%d", &n); for (i = 0; i < n; i++) { scanf("%d", &arr[i]); } qsort(arr, n, sizeof(int), compare_int); for (i = 0; i < 5; i++) { printf("%d ", arr[i]); } return 0; }