求第k大数
#include<bits/stdc++.h> using namespace std; int n,k,a[10000]; int qsort(int l,int r,int k) { int key=a[r]; int i=l,j=r; while(i!=j) { while(i<j&&a[i]<=key)i++; while(i<j&&a[j]>=key)j--; if(i<j) swap(a[i],a[j]); } a[r]=a[i]; a[i]=key; if(k==i-l+1) return a[i]; if(k<i-l+1&&l<=i-1)return qsort(l,i-1,k); if(k>i-l+1&&i+1<=l)return qsort(i+1,r,k-(i-l+1)); } int main() { cin>>n>>k; for(int i=1;i<=n;i++) { cin>>a[i]; } cout<<qsort(1,n,k); }