zoukankan      html  css  js  c++  java
  • unique函数

    学习链接:https://www.cnblogs.com/hua-dong/p/7943983.html

    unique用来去掉数组中相邻的重复的元素 被包含在algorithm头文件中

    看代码:

    #include<iostream>
    #include<algorithm>
    using namespace std;
    typedef long long LL;
    const int maxn=1e5+50;
    const LL INF=1e18;
    int main()
    {
        int a[10]={1,1,2,2,3,3,4,4,5,5};
      sort(a,a+10);
    int len=unique(a,a+10)-a; for(int i=0;i<len;i++) cout<<a[i]<<" ";cout<<endl;//1 2 3 4 5 // for(int i=0;i<10;i++) cout<<a[i]<<" ";cout<<endl; return 0; }

     当数组从1开始存储时,看下面的情况:

    #include<iostream>
    #include<algorithm>
    using namespace std;
    typedef long long LL;
    const int maxn=1e5+50;
    const LL INF=1e18;
    int main()
    {
        int a[15]={1,1,1,2,2,3,3,4,4,5,5};
    sort(a,a+10);
    int len=unique(a+1,a+10+1)-(a+1);//len说的是有多少个 cout<<len<<endl;//5 for(int i=1;i<=len;i++) cout<<a[i]<<" ";cout<<endl;//1 2 3 4 5 // for(int i=0;i<10;i++) cout<<a[i]<<" ";cout<<endl; return 0; }
    当初的梦想实现了吗,事到如今只好放弃吗~
  • 相关阅读:
    二极管常用
    金属化孔与非金属化孔
    电容~3.钽电容
    电感~2.电路分析
    交流整流之后
    电容~2.电路分许
    三极管~3常见电路
    三极管~2.电路分析
    名词解释
    硬件设计
  • 原文地址:https://www.cnblogs.com/caijiaming/p/10890441.html
Copyright © 2011-2022 走看看