Lawate @ 2022-11-25 16:26:25
#include<iostream>
using namespace std;
int a[5000001];
void qsort(int l, int r, int k)
{
int flag = a[(l + r) / 2];
int i = l, j = r;
do
{
while (a[i] < flag)
{
i++;
}
while (a[j] > flag)
{
j--;
}
if (i <= j)
{
int t;
t = a[i];
a[i] = a[j];
a[j] = t;
i++;
j--;
}
} while (i <= j);
if (k >= i)
{
qsort(i, r, k);
}
else if (k <= j)
{
qsort(l, j, k);
}
else if (k > j && k < i)//在i,j中间
{
cout << a[k+1];//这里这里
return;
}
}
int main()
{
int n, k;
cin >> n >> k;
for (int q = 0; q < n; q++)
{
cin >> a[q];
}
qsort(0, n, k);
return 0;
}
谢谢大佬!
by wkl20110514 @ 2022-12-09 11:48:01
@Lawate 题目说的是最小的数是第0小