题解 | #争夺前五名#
争夺前五名
https://www.nowcoder.com/practice/cd052308a1c44a88ad00255f312c3e14
#include <stdio.h> int main() { int n = 0; int arr[50] = {0}; while (1 == scanf("%d", &n)) { // 输入数据 for (int i = 0; i < n; i++) { scanf("%d", &arr[i]); } // 冒泡排序:升序 for (int i = 0; i < n; i++) { for (int j = 0; j < n - i - 1; j++) { if (arr[j] > arr[j + 1]) { int tmp = arr[j]; arr[j] = arr[j + 1]; arr[j + 1] = tmp; } } } // 输出 for (int i = n - 1; i >= n -5; i--) { printf("%d ", arr[i]); } } return 0; }