3036: 【普及-】【P4305】不重复数字

内存限制:128 MB 时间限制:1.000 S
评测方式:文本比较 命题人:
提交:7 解决:3

题目描述

给定 lns="http://www.w3.org/1998/Math/MathML"> 个数,要求把其中重复的去掉,只保留第一次出现的数。

输入

本题有多组数据。

第一行一个整数 lns="http://www.w3.org/1998/Math/MathML">,表示数据组数。

对于每组数据:

第一行一个整数 lns="http://www.w3.org/1998/Math/MathML">

第二行 lns="http://www.w3.org/1998/Math/MathML"> 个数,表示给定的数。

输出

对于每组数据,输出一行,为去重后剩下的数,两个数之间用一个空格隔开。

样例输入 复制

2
11
1 2 18 3 3 19 2 3 6 5 4
6
1 2 3 4 5 6

样例输出 复制

1 2 18 3 19 6 5 4
1 2 3 4 5 6

提示

对于 lns="http://www.w3.org/1998/Math/MathML">30% 的数据,lns="http://www.w3.org/1998/Math/MathML">100,给出的数 lns="http://www.w3.org/1998/Math/MathML">[0,100]

对于 lns="http://www.w3.org/1998/Math/MathML">60% 的数据,lns="http://www.w3.org/1998/Math/MathML">104,给出的数 lns="http://www.w3.org/1998/Math/MathML">[0,104]

对于 lns="http://www.w3.org/1998/Math/MathML">100% 的数据,lns="http://www.w3.org/1998/Math/MathML">150lns="http://www.w3.org/1998/Math/MathML">15×104,给出的数在 lns="http://www.w3.org/1998/Math/MathML">32 位有符号整数范围内。

#include<bits/stdc++.h>
using namespace std;
#define MAXN 50010
int T,n,t;
int a[MAXN];
int main(){
    cin >> T;
    while (T--) {
    	cin >> n;
    	set <int> ds;
    	int cnt = 0;
    	for (int i = 1; i <= n; i++) {
    		cin >> t;
    		if (ds.find(t) == ds.end()) {
    			ds.insert(t);
    			a[++cnt] = t;
			}
		}
		for (int i = 1; i <= cnt ; i++) {
			cout << a[i] << " ";
		}
		cout << endl;
	}
	return 0;
}