题目描述】
现在有n个数,请问其中严格第k小的数是多少,其中严格第k小指对这些数去重以后的第k小。
【输入】
第一行两个整数n,k(1≤k≤n≤105)。
第二行n个整数a(1≤ai≤109)表示n个数。
【输出】
输出一行,包含一个整数,表示答案
输入保证有解。
【输入样例】
5 3
1 2 3 2 4
【输出样例】
3
#include<iostream>
#include<algorithm>
#include <set>
using namespace std;
set<int> b_set;
int cnt;
int main()
{
int num,k;
cin>>num>>k;
int a[num];
for(int i=0;i<num;i++)
{
cin>>a[i];
//去重复的数
b_set.insert(a[i]);
}
sort(a,a+num);
// 使用迭代器遍历集合
for ( set<int>::iterator it = b_set.begin(); it != b_set.end(); ++it) {
cnt++;
if (cnt==k) {
cout << *it << " ";
}
}
//cout << '\n';
//cout<<a[k-1];
return 0;
}