题解 | #争夺前五名#
争夺前五名
https://www.nowcoder.com/practice/cd052308a1c44a88ad00255f312c3e14
#include <stdio.h> int main() { int n = 0; scanf("%d", &n); int score[50] = {0}; //存储成绩 size_t i = 0; for(i = 0; i < n; ++i) { //getchar(); scanf("%d", &score[i]); } //成绩排序 for(i = 0; i < n-1; ++i)//冒泡排序趟数 { size_t j = 0; for(j = 0; j < n-1-i; ++j)//每趟对比个数 { if(score[j] < score[j+1]) { int tmp = score[j]; score[j] = score[j+1]; score[j+1] = tmp; } } } //输出前五名 for(i = 0; i < 5; ++i) { printf("%d ", score[i]); } printf("\n"); return 0; }