Problem P04. [算法课分治] 找到 k 个最小数
作者:互联网
先
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 来源: https://www.cnblogs.com/understanding-friends/p/16651845.html