Problem P05. [算法课分治] 寻找第 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);
printf("%d", arr[n-k]);
return 0;
}
标签:sort,arr,元素,int,scanf,分治,P05,Problem,include 来源: https://www.cnblogs.com/understanding-friends/p/16651847.html