60pts求助!
查看原帖
60pts求助!
195705
李湛然楼主2021/3/10 18:59
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
int T;
int n;
const int N=5*1e4+10;
int a[N];
const int mod=114514;
int hsh[mod+1];
inline bool Hash(int x)
{
	if(hsh[((x%mod)+mod)%mod]>0)
	{
		return false;
	} 
	else
	{
		hsh[((x%mod)+mod)%mod]=1;
		return true;
	}
}
int main()
{
	cin>>T;
	while(T--)
	{
		cin>>n;
		memset(hsh,0,sizeof(hsh));
		for(int i=1;i<=n;i++)
		{
			scanf("%lld",&a[i]);
		}
		for(int i=1;i<=n;i++)
		{
			if(Hash(a[i]))
			{
				printf("%lld ",a[i]); 
			}
		}
		printf("\n");
	}
	return 0;
} 
2021/3/10 18:59
加载中...