3\10求挑错
查看原帖
3\10求挑错
1429512
Silent_Lamb楼主2024/8/27 20:35
#include <bits/stdc++.h>
using namespace std;
int a[100000];
void qsort(int low,int high){
    if(low>=high) return;
    int i=low,j=high,t=a[(low+high)/2];
    while(i<=j){
        while(a[i]<t) i++;
        while(a[j]>t) j--;
        if(i<=j) swap(a[i++],a[j--]);
    }
    qsort(low,j);
    qsort(i,high); 
      
}
   
  
  
int main(){
    int n,k;
    cin>>n>>k;
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    qsort(0,n-1);
    int t=0;
    for(int i=0;i<n;i++){
		if(i==0||a[i]==a[i-1])t++;
    	if(t==k){
    		cout << a[i];
    		return 0;
		}
	}
	cout << "NO RESULT";
	return 0;
}
2024/8/27 20:35
加载中...