zoukankan      html  css  js  c++  java
  • BZOJ2761:[JLOI2011]不重复数字(map)

    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

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

    Sample Output

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

    HINT

    对于30%的数据,1 <= N <= 100,给出的数不大于100,均为非负整数;

    对于50%的数据,1 <= N <= 10000,给出的数不大于10000,均为非负整数;

    对于100%的数据,1 <= N <= 50000,给出的数在32位有符号整数范围内。

    提示:

    由于数据量很大,使用C++的同学请使用scanfprintf来进行输入输出操作,以免浪费不必要的时间。

    Solution

    实在不想做这个题就从网上随便粘了一篇交上去了=v=

    Code

     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("
    ");
    40     }
    41     return 0;
    42 }
  • 相关阅读:
    postgresql 添加触发器
    postgresql 操作
    postgresql 更新自增变量
    java8 stream api 文件流甚是牛逼
    fastjson妙用
    idea中springboot内置tomcat控制台中文乱码解决
    linux中开放某个端口
    idea中application.properties文件防止中文汉字自动转换成unicode编码解决办法
    使用vue开源项目vue-framework-wz遇到的问题以及解决方案
    rsync的使用
  • 原文地址:https://www.cnblogs.com/refun/p/8685584.html
Copyright © 2011-2022 走看看