先
sort
排序,在输出最小的k
个数。
#include<iostream>
#include<bits/stdc++.h>
#include<cstdio>
using namespace std;
int n, k;
int arr[10005];
int main()
{
scanf("%d %d", &n, &k);
for (int i = 0; i < n; i++){
scanf("%d", &arr[i]);
}
sort(arr, arr+n);
for (int i = 0; i < k; i++){
printf("%d ", arr[i]);
}
return 0;
}
标签:sort,arr,int,scanf,分治,P04,Problem,include
From: https://www.cnblogs.com/understanding-friends/p/16651845.html