BZOJ 2761 set
题
题意:给一个数列,只保留第一次出现的数。
解
本来临睡前不想做题的结果看到这道= =
set 入门运用。
一不小心就 Presentation Error... 是不是意味着我不适合去做 presentation ……
码(1088 kb 716 ms)
#include <cstdio>
#include <set>
using namespace std;
template<class T>
inline void read(T& x)
{
char c = getchar(); T p = 1, n = 0;
while(c < '0' || c > '9'){if(c == '-') p = -1; c = getchar();}
while(c >= '0' && c <= '9'){n = n * 10 + c - '0'; c = getchar();}
x = p * n;
}
template<class T, class U>
inline void read(T& x, U& y){read(x), read(y);}
template<class T, class U, class V>
inline void read(T& x, U& y, V& z){read(x), read(y), read(z);}
set<int> s;
int main()
{
int t; read(t);
while(t--)
{
s.clear();
int n; read(n);
bool flag = false;
while(n--)
{
int x; read(x);
if(s.find(x) == s.end()){if(flag) putchar(' '); printf("%d", x), s.insert(x); flag = true;}
}
puts("");
}
return 0;
}