简单的知识,复杂的代码
2025-05-12 16:22:51
发布于:浙江
0阅读
0回复
0点赞
这题只要排好序,不重复就行。代码:
#include<bits/stdc++.h>
using namespace std;
int n, k, a[100005], cnt;
int main() {
cin >> n >> k;
for (int i = 1; i <= n; i++)cin >> a[i];
for (int i = 1; i <= n; i++) {
for (int j = 1; j < n; j++) {
if (a[j] > a[j + 1]) {
swap(a[j], a[j + 1]);
}
}
}
for (int i = 1; i <= n; i++) {
if (a[i] != a[i - 1]) {
cnt++;
if(cnt==k){
cout<<a[i];
return 0;
}
}
}
cout<<"NO RESULT";
return 0;
}
这里空空如也
有帮助,赞一个