不同的数
题目 不同的数
思路分析
因为要原本的下标 而不是输出值本身
所以得用键值对 一个存值 作为key判重 一个存原本下标 用于输出
用unordered_map
代码实现
#include<bits/stdc++.h>
using namespace std;
const int N=110;
unordered_map<int,int> h;
int n,k;
int main()
{
cin>>n>>k;
for(int i=1;i<=n;i++){
int a;
cin>>a;
h[a]=i;
}
if(h.size()<k)
puts("NO");
else{
puts("YES");
int cnt=0;
for(auto item:h){
cout<<item.second<<" ";
++cnt;
if(cnt==k)
break;
}
}
return 0;
}
💬 评论