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 65 66 67 68
|
#include <iostream>
#include <string>
#include <vector>
#include <iterator>
#include <algorithm>
#include <utility>
#include <cassert>
#include <fstream>
#include <stdio.h>
struct LC_413
{
LC_413() {}
std::string x;
std::string a;
std::string y;
std::string z;
std::string e;
std::string b;
std::string c;
LC_413( const std::string& x, const std::string& a, const std::string& y, const std::string& z, const std::string& e, const std::string& b,
const std::string& c): x(x), a(a), y(y), z(z), e(e), b(b), c(c) {}
};
struct only_unique // : std::unary_function<LC_413,bool>
{
explicit only_unique( const LC_413& lc413 ) : a(lc413) {}
bool operator() ( const LC_413& b ) const
{
//return a.x==b.x && a.a==b.a && a.y==b.y && a.z!=b.z && a.e!=b.e && a.b==b.b && a.c==b.c;
return a.x==b.x && a.z!=b.z && a.e!=b.e;
}
private: const LC_413& a ;
};
std::ostream& operator<< ( std::ostream& stm, const LC_413& a )
{ return stm << '[' << a.x << ", " << a.a << ", " << a.y << ", " << a.z << ", " << a.e << ", " << a.b << ", " << a.c << ']' ; }
int main()
{
std::vector<LC_413> v1;
v1.push_back(LC_413("A", "w", "k", "917", "B", "g", "p"));
v1.push_back(LC_413("A", "x", "l", "917", "B", "h", "q"));
v1.push_back(LC_413("A", "y", "m", "916", "S", "i", "r"));
v1.push_back(LC_413("A", "z", "n", "916", "S", "j", "s"));
// find out those elements where x, y, z are equal but 'a' is different.
for( std::vector<LC_413>::size_type i = 0 ; i < v1.size(); ++i )
{
std::cout << v1[i] << " => " ;
std::vector<LC_413>::iterator iter
= std::find_if( v1.begin(), v1.end(), only_unique(v1[i]) ) ;
while( iter != v1.end() )
{
std::cout << *iter ;
iter = std::find_if( ++iter, v1.end(), only_unique(v1[i]) ) ;
break;
}
std::cout << '\n';
}
}
|