题目:
方案一:sort排序
#include<bits/stdc++.h>
using namespace std;int main()
{int n;int k;cin>>n>>k;int a[n]={0};for(int i=0;i<n;i++){cin>>a[i];}sort(a,a+n); cout<<a[k]<<endl;}
方案二:nth_element
#include<bits/stdc++.h>
using namespace std;int main()
{int n;int k;cin>>n>>k;int a[n]={0};for(int i=0;i<n;i++){cin>>a[i];}nth_element(a,a+k,a+n); cout<<a[k]<<endl;}