C++ unique
#include <iostream>
#include <algorithm>
#include <list>
#include <iterator>
#include <functional>
using namespace std;
int main()
{
int source[] = { 1,2,3,3,3,4,5,6,6,7,8,8,8,9,10,3,6,8,12 };
int sourceNum = sizeof(source)/sizeof(source[0]);
list<int> list1;
list<int> list2;
copy(source,source+sourceNum,back_inserter(list1));
copy(source,source+sourceNum,back_inserter(list2));
list<int>::iterator list_iter1;
for (list_iter1 = list1.begin();list_iter1 != list1.end(); ++list_iter1)
{
cout << *list_iter1 << " ";
}
cout << endl;
cout << "----------------------------------------------" << endl;
list<int>::iterator list_iter2;
list_iter2 = unique(list1.begin(),list1.end());
for (list_iter1 = list1.begin();list_iter1 != list_iter2; ++list_iter1)
{
cout << *list_iter1 << " ";
}
cout << endl;
cout << "----------------------------------------------" << endl;
list<int>::iterator list_iter3 = unique(list2.begin(),list2.end(),greater<int>());
for (list_iter1 = list2.begin(); list_iter1 != list_iter3; ++list_iter1)
{
cout << *list_iter1 << " ";
}
cout << endl;
cout << "----------------------------------------------" << endl;
system("pause");
return 0;
}
================================================
1 2 3 3 3 4 5 6 6 7 8 8 8 9 10 3 6 8 12
----------------------------------------------
1 2 3 4 5 6 7 8 9 10 3 6 8 12
----------------------------------------------
1 2 3 3 3 4 5 6 6 7 8 8 8 9 10 12
----------------------------------------------
请按任意键继续. . .
C++ unique的更多相关文章
- [LeetCode] Unique Substrings in Wraparound String 封装字符串中的独特子字符串
Consider the string s to be the infinite wraparound string of "abcdefghijklmnopqrstuvwxyz" ...
- [LeetCode] Minimum Unique Word Abbreviation 最短的独一无二的单词缩写
A string such as "word" contains the following abbreviations: ["word", "1or ...
- [LeetCode] Count Numbers with Unique Digits 计算各位不相同的数字个数
Given a non-negative integer n, count all numbers with unique digits, x, where 0 ≤ x < 10n. Examp ...
- [LeetCode] Unique Word Abbreviation 独特的单词缩写
An abbreviation of a word follows the form <first letter><number><last letter>. Be ...
- [LeetCode] Unique Binary Search Trees 独一无二的二叉搜索树
Given n, how many structurally unique BST's (binary search trees) that store values 1...n? For examp ...
- [LeetCode] Unique Binary Search Trees II 独一无二的二叉搜索树之二
Given n, generate all structurally unique BST's (binary search trees) that store values 1...n. For e ...
- [LeetCode] Unique Paths II 不同的路径之二
Follow up for "Unique Paths": Now consider if some obstacles are added to the grids. How m ...
- [LeetCode] Unique Paths 不同的路径
A robot is located at the top-left corner of a m x n grid (marked 'Start' in the diagram below). The ...
- 2 Unique Binary Search Trees II_Leetcode
Given n, generate all structurally unique BST's (binary search trees) that store values 1...n. For e ...
- Constraint5:unique 约束和null
unique约束使用unique index来限制列值的唯一性: 创建unique约束之后,column中允许插入null值,unique 约束将两个null值看作是相同的(即null=null为tr ...
随机推荐
- Flutter——AppBar组件(顶部导航组件)
AppBar组件的常用属性如下: 属性 描述 leading 在标题前面显示的一个控件,在首页通常显示应用的 logo:在其他界面通常显示为返回按钮 title 标题,通常显示为当前界面的标题文字,可 ...
- arduino安装出现驱动程序不适用于该平台
之前重新安装了系统,然后重新安装arduino驱动的时候出现了之前没遇到过的问题,这里记录一下. 现在装的是win7 64位的系统,先去官方下载(官方下载慢的,可以去相关论坛下载),有安装版和解压版的 ...
- Java&Selenium数据驱动【DataProvider+TestNG+Excel】
Java&Selenium数据驱动[DataProvider+TestNG+Excel] package testNGWithDataDriven; import java.io.File; ...
- spring replaced method 注入
replaced method注入是spring动态改变bean里方法的实现.需要改变的方法,使用spring内原有其他类(需要继承接口org.springframework.beans ...
- post和get的在测试眼里的区别大概就是post比get安全吧……
get将请求数据放在url中,而post将请求数据放在request body中 http://www.cnblogs.com/logsharing/p/8448446.html
- 2019HDU多校第三场 K subsequence——最小费用最大流
题意 给定一个 $n$ 个整数的数列,从中至多选取 $k$ 个上升子序列(一个元素最多被选一次),使得选取的元素和最大. 分析 考虑这个问题和经典网络流问题“最长不下降子序列”相似,我们考虑对这个建图 ...
- adb端口被自己占用,或者用adb连不上模拟器最终解决办法
1.下载360手机助手 2.找一个安卓手机连接上电脑,安装驱动 3.手机助手可以连接手机 4.拔掉手机开启模拟器以后都可以用adb连接模拟器了 找到占用端口的程序,禁止其运行 1.首先找到占用5037 ...
- dblclick([[data],fn]) 当双击元素时,会发生 dblclick 事件。
dblclick([[data],fn]) 概述 当双击元素时,会发生 dblclick 事件.大理石量具哪家好 当鼠标指针停留在元素上方,然后按下并松开鼠标左键时,就会发生一次 click.在很短的 ...
- SpingMVC入门
Springmvc简介及配置 1. 什么是springMVC? Spring Web MVC是一种基于Java的实现了MVC设计模式的.请求驱动类型的.轻量级Web框架. 2. SpringMVC处理 ...
- .netcore signalR 实时消息推送
服务器端引入包 Install-Package Microsoft.AspNetCore.SignalR客户端引入包 npm install @aspnet/signalr <template ...