#include<bits/stdc++.h>
using namespace std;
int a[1050],hash[1050];
int main()
{
int n,k=0;
scanf("%d",&n);
for(int i=0; i<n; i++)
scanf("%d",&a[i]);
memset(hash,0,sizeof(hash));
for(int i=0; i<n; i++)
{
if(hash[a[i]]==0)
{
k++;
hash[a[i]]=1;
}
}
printf("%d\n",k);
memset(hash,0,sizeof(hash));
for(int i=0; i<n; i++)
{
if(hash[a[i]]==0)
{
if(i!=0)printf(" ");
printf("%d",a[i]);
hash[a[i]]=1;
}
}
}
SDUT1130数据结构上机测试1:顺序表的应用(上一个代码太蠢)
最新推荐文章于 2020-11-16 18:48:59 发布
本文提供了一个使用C++实现的简单程序,该程序能够读取一组整数并输出其中不重复元素的数量及具体数值。通过两次遍历数组并利用hash表标记已出现过的元素来实现去重。

349

被折叠的 条评论
为什么被折叠?



