首页 > 编程语言 >Problem P04. [算法课分治] 找到 k 个最小数

Problem P04. [算法课分治] 找到 k 个最小数

时间:2022-09-03 02:33:28浏览次数:60  
标签:sort arr int scanf 分治 P04 Problem include

image

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

相关文章