zoukankan      html  css  js  c++  java
  • BZOJ 2761: [JLOI2011]不重复数字 set

    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

     
    对于每组数据,输出一行,为去重后剩下的数字,数字之间用一个空格隔开。
    题解:每次用 $set$ 查询一个数是否插入过即可. 
    #include<bits/stdc++.h>
    #define maxn 100000 
    using namespace std;
    void setIO(string s)
    {
    	string in=s+".in"; 
    	freopen(in.c_str(),"r",stdin); 
    }
    set<int>S; 
    set<int>::iterator it; 
    int arr[maxn]; 
    inline void solve()
    {
    	int n,i,a; 
    	scanf("%d",&n); 
    	for(i=1;i<=n;++i) 
    	{
    		scanf("%d",&a); 
    		if(S.find(a)==S.end()) printf("%d ",a), S.insert(a); 
    	}
    	S.clear(); 
    	printf("
    "); 
    }
    int main()
    {
    	// setIO("input"); 
    	int T; 
    	scanf("%d",&T); 
    	while(T--) solve(); 
    	return 0; 
    }
    

      

  • 相关阅读:
    我的省选 Day -9
    我的省选 Day -10
    我的省选 Day -11
    我的省选 Day -12
    我的省选 Day -13
    [NOI2013]快餐店
    我的省选 Day -14
    杭电多校2020第7场-E Expectation
    「联合省选2020」组合数问题
    UR#19 通用评测号
  • 原文地址:https://www.cnblogs.com/guangheli/p/11093406.html
Copyright © 2011-2022 走看看