先
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
From: https://www.cnblogs.com/understanding-friends/p/16651847.html