1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
|
#include <iostream>
#include <string>
#include <vector>
#include <iterator>
#include <algorithm>
using namespace std;
struct LC_413
{
std::string x;
std::string a;
std::string y;
std::string z;
LC_413(const std::string& x, const std::string& a, const std::string& y, const std::string& z): x(x), a(a), y(y), z(z) {}
bool operator==(const LC_413& p) const
{
return x == p.x && a == p.a && y == p.y && z == p.z;
}
bool operator<(const LC_413& p) const
{
if(x < p.x) return true;
if(x > p.x) return false;
if(y < p.y) return true;
if(y > p.y) return false;
if(z < p.z) return true;
if(z > p.z) return false;
return false;
}
};
int main()
{
std::vector<LC_413> v1;
v1.push_back(LC_413("a", "1", "a", "c"));
v1.push_back(LC_413("a", "2", "b", "b"));
v1.push_back(LC_413("a", "2", "a", "c"));
v1.push_back(LC_413("b", "3", "a", "c"));
v1.push_back(LC_413("a", "0", "b", "b"));
v1.push_back(LC_413("b", "6", "b", "h"));
v1.push_back(LC_413("b", "4", "b", "h"));
v1.push_back(LC_413("b", "9", "b", "h"));
v1.push_back(LC_413("a", "1", "a", "c"));
std::sort(v1.begin(), v1.end());
std::pair<std::vector<LC_413>::iterator, std::vector<LC_413>::iterator> ret;
for(std::vector<LC_413>::iterator i = v1.begin(); i != v1.end(); i = ret.second)
{
std::cout << "[" << i->x << ", " << i->a << ", " << i->y << ", " << i->z << "] => ";
ret = std::equal_range(i, v1.end(), *i);
for(std::vector<LC_413>::iterator j = ret.first; j != ret.second; ++j)
{
std::cout << "[" << j->x << ", " << j->a << ", " << j->y << ", " << j->z << "]";
}
std::cout << '\n';
}
}
|