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 ...
随机推荐
- Android 启动流程分析
原文:https://www.jianshu.com/p/a5532ecc8377 作者曾经在高通的Android性能组工作,主要工作是优化Android Application的启动时间. APP基 ...
- 常用git指令记录
Generating an SSH key Checking for existing SSH keys Generating a new SSH key and adding it to the s ...
- [Selenium3+python3.6]自动化测试3-八种元素元素定位(Firebug和firepath)
参考http://www.cnblogs.com/yoyoketang/p/6123890.html #coding=utf-8 from selenium import webdriverdri ...
- python-----图片保存为视频
#!/usr/bin/env python # -*- coding: utf-8 -*- # @Time : 2019/7/2 13:32 # @Author : xiaodai # -*- cod ...
- asp.netMVC中使用aop进行关注点分离
资源地址:https://stackoverflow.com/questions/23244400/aspect-oriented-programming-in-asp-net-mvc 从页面复制过来 ...
- Window脚本学习笔记之BAT文件处理
BAT文件处理 列出盘中特定文件名的文件: @echo offdir C:\*.jpg /b/s>.\CDatejpg.txt dir C:\*.png /b/s>.\CDatepng.t ...
- 模拟一个http 请求的json格式报文,带 rsa 签名操作
一.对需要加密的字符串,定义RsaSignUnsign 类,代码如下: 实现了: 1.实现了生成新的pubkey.pri_key方法: 2.将新生成的keys 写入文件: 3.从文件获取pubkey. ...
- Jupyter的学习
一 .Jupyter中的魔术命令 %load test.py :”可以将test.py 中的文件加载到jupyter框中 %matplotlib inline :可以将Matplotlib 的结果嵌 ...
- Spring-Spring配置-依赖注入
5.Spring配置 5.1.别名 <!--别名,如果添加了别名,我们也可以使用别名获取到这个对象--> <alias name="user" alias=&qu ...
- flask 杂记
参考资料:http://python.jobbole.com/84003/ https://flask-cn.readthedocs.io/en/latest/tutorial/ 加载配置: app ...