2761. [JLOI2011]不重復數字【map】
阿新 • • 發佈:2018-04-01
要去 getch 浪費 不重復 正整數 數字 Go time for
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
Description
給出N個數,要求把其中重復的去掉,只保留第一次出現的數。 例如,給出的數為1 2 18 3 3 19 2 3 6 5 4,其中2和3有重復,去除後的結果為1 2 18 3 19 6 5 4。Input
輸入第一行為正整數T,表示有T組數據。 接下來每組數據包括兩行,第一行為正整數N,表示有N個數。第二行為要去重的N個正整數。Output
對於每組數據,輸出一行,為去重後剩下的數字,數字之間用一個空格隔開。Sample Input
211
1 2 18 3 3 19 2 3 6 5 4
6
1 2 3 4 5 6
Sample Output
1 2 3 4 5 6
HINT
對於30%的數據,1 <= N <= 100,給出的數不大於100,均為非負整數;
對於50%的數據,1 <= N <= 10000,給出的數不大於10000,均為非負整數;
對於100%的數據,1 <= N <= 50000,給出的數在32位有符號整數範圍內。
提示:
由於數據量很大,使用C++的同學請使用scanf和printf來進行輸入輸出操作,以免浪費不必要的時間。
實在不想做這個題就從網上隨便粘了一篇交上去了=v=
1 #include <iostream> 2#include <cstring> 3 #include <cstdlib> 4 #include <cstdio> 5 #include <algorithm> 6 #include <map> 7 #include <vector> 8 #define ll long long 9 using namespace std; 10 const int MAXN = 50000 + 10; 11 int read() 12 { 13 int x = 0, f = 1; char ch = getchar();14 while(ch < ‘0‘ || ch > ‘9‘){if(ch == ‘-‘) f *= -1; ch = getchar();} 15 while(ch >= ‘0‘ && ch <= ‘9‘){x = x * 10 + ch - ‘0‘; ch = getchar();} 16 return x * f; 17 } 18 map<int, int> st; 19 int N, x; 20 int main() 21 { 22 int T = read(); 23 while(T--) 24 { 25 N = read(); 26 st.clear(); 27 bool flag = true; 28 for(int i=0; i<N; i++) 29 { 30 x = read(); 31 if(st[x] == 0) 32 { 33 if(!flag) printf(" "); 34 printf("%d", x); 35 flag = false; 36 } 37 st[x] = 1; 38 } 39 printf("\n"); 40 } 41 return 0; 42 }
2761. [JLOI2011]不重復數字【map】