Information
- ID
- 1756
- Time
- 1000ms
- Memory
- 512MiB
- Difficulty
- 10
- Tags
- # Submissions
- 7
- Accepted
- 4
- Uploaded By
排序过后进行两次清零操作
#include <bits/stdc++.h>
using namespace std;
int vis[10001];
int main()
{
int arr[101],n,sum=0;
cin>>n;
for(int i=0;i<n;i++)
{
cin>>arr[i];
}
sort(arr,arr+n);
memset(vis,0,sizeof(vis));
for(int i=0;i<n;i++)
{
if(vis[arr[i]]==0)
{
sum++;
vis[arr[i]]=1;
}
}
memset(vis,0,sizeof(vis));
cout<<sum<<endl;
cout<<arr[0];
vis[arr[0]]=1;
for(int i=0;i<n;i++)
{
if(vis[arr[i]]==0)
{
cout<<" "<<arr[i];
vis[arr[i]]=1;
}
}
return 0;
}
By signing up a 追梦算法网 universal account, you can submit code and join discussions in all online judging services provided by us.