华为机试题2
2015-09-20 18:34
239 查看
数组去重并排序
思路:先去重后排序或者先排序后去重
可以使用STL来求,set内部是有序的,list内部不是有序的。
样例:
输入:
4
6 3 3 9
输入
3 6 9
View Code
思路:先去重后排序或者先排序后去重
可以使用STL来求,set内部是有序的,list内部不是有序的。
样例:
输入:
4
6 3 3 9
输入
3 6 9
#include <iostream> #include <algorithm> #include <set> #include <list> using namespace std; void RemoveRep(int arr[],int N) { set<int> s; pair< set<int>::iterator, bool > m; list<int> list1; for(int i=0;i<N;i++){ m=s.insert(arr[i]); if(m.second) list1.push_back(arr[i]); } for(set<int>::iterator it=s.begin();it!=s.end(); it++) cout<<*it<<" "; } int main() { int a[4] = {6,3,3,9}; RemoveRep(a,4); return 0; }
View Code
相关文章推荐
- Keepalive实现Mysql主主复制,高可用群集
- HD 5455 FangFang
- C++ 数组
- 【codevs】2918
- yaffs2文件镜像制作工具yaffs2image
- 软工实践练习——使用git进行代码管理心得
- 数据库语句总结(2)
- BA--暖通系统常见设计细节要点
- mysql授权
- Java学习手手记-一元二次函数解法
- 二维数组取值
- Web Service 那点事儿
- Flex在使用无线电的button切换直方图横坐标和叙述性说明
- 博客从博客园迁移到github上
- Linux中的僵死进程(02)---wait回收僵死进程
- 腾讯auth认证
- 解决configure build path问题
- 新的我
- 函数指针与指针函数
- VxWorks基础知识