问题描述:
代码示例:
#include <bits/stdc++.h>
using namespace std;int main(){cout << "样例输入" << endl; int n;int m;cin >> n;int nums[n];for(int i = 0; i < n; i++){cin >> nums[i];}// 排序for(int i = 0; i < n; i++){//冒泡 for(int j = i+1; j < n; j++){if(nums[i] < nums[j]){//交换 int temp = nums[i];nums[i] = nums[j];nums[j] = temp;}}}// 去重int k = 0;for(int i = 1; i < n; i++){if(nums[k] != nums[i]){nums[++k] = nums[i];}} // 遍历
// for(int i = 0; i <= k; i++){
// cout << nums[i] << " ";
// } //测试成功 cin >> m; cout << "样例输出" << endl; if(m <= k+1){cout << nums[m-1];}else{cout << "不存在";}return 0;
}
运行结果: