#include "stdafx.h"
#include <iostream>
#include <list>
typedef std::pair<int, int> IntPair;
typedef std::list<IntPair> LstIntPair;
inline std::ostream& operator << (std::ostream& stream, IntPair& val)
{
stream << "(" << val.first << (", ") << val.second << ")";
return stream;
};
void main()
{
LstIntPair lstVal;
lstVal.push_back(std::make_pair(1, 1));
lstVal.push_back(std::make_pair(1, 3));
lstVal.push_back(std::make_pair(1, 3));
lstVal.push_back(std::make_pair(1, 2));
lstVal.push_back(std::make_pair(1, 1));
lstVal.push_back(std::make_pair(1, 6));
lstVal.push_back(std::make_pair(1, 5));
lstVal.push_back(std::make_pair(2, 1));
lstVal.push_back(std::make_pair(2, 3));
lstVal.push_back(std::make_pair(2, 3));
lstVal.push_back(std::make_pair(2, 2));
lstVal.push_back(std::make_pair(2, 1));
lstVal.push_back(std::make_pair(2, 6));
lstVal.push_back(std::make_pair(2, 5));
lstVal.sort();
lstVal.unique();
LstIntPair::iterator it;
for (it = lstVal.begin(); it != lstVal.end(); ++ it)
{
std::cout << *it << std::endl;
}
}
输出:
(1, 1)
(1, 2)
(1, 3)
(1, 5)
(1, 6)
(2, 1)
(2, 2)
(2, 3)
(2, 5)
(2, 6)
请按任意键继续. . .
利用pair,sort,unique去重
最新推荐文章于 2024-02-05 18:39:40 发布