Created
September 18, 2012 15:10
-
-
Save yifu/3743661 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <algorithm> | |
#include <iostream> | |
#include <iterator> | |
#include <string> | |
#include <utility> | |
#include <vector> | |
using namespace std; | |
// -------------------------------------------------------------------------- | |
namespace std | |
{ | |
ostream& operator << (ostream& os, const pair<string,string>& p) | |
{ | |
return os << p.first << "," << p.second; | |
} | |
} | |
// -------------------------------------------------------------------------- | |
inline bool key_comp(const pair<string,string>& l, const pair<string,string>& r) { return l.first < r.first; } | |
// -------------------------------------------------------------------------- | |
inline bool val_comp(const pair<string,string>& l, const pair<string,string>& r) { return l.second < r.second;} | |
// -------------------------------------------------------------------------- | |
int main() | |
{ | |
vector<pair<string,string> > dict; | |
/* | |
dict.push_back(make_pair("43", "3toto")); | |
dict.push_back(make_pair("43", "1toto")); | |
dict.push_back(make_pair("43", "2toto")); | |
dict.push_back(make_pair("43", "toto")); | |
dict.push_back(make_pair("42", "test3")); | |
dict.push_back(make_pair("42", "test1")); | |
dict.push_back(make_pair("42", "test2")); | |
dict.push_back(make_pair("42", "test")); | |
dict.push_back(make_pair("D3", "f3dfgdfg")); | |
dict.push_back(make_pair("D3", "f1df")); | |
dict.push_back(make_pair("D3", "2fff")); | |
dict.push_back(make_pair("D3", "")); | |
dict.push_back(make_pair("D3", "ffdf3")); | |
dict.push_back(make_pair("D3", "1d")); | |
dict.push_back(make_pair("D3", "2")); | |
dict.push_back(make_pair("D3", "sdfs")); | |
*/ | |
dict.push_back(make_pair("08","FR0010342592")); | |
dict.push_back(make_pair("16","FR0000039091")); | |
dict.push_back(make_pair("18","FR0007080973")); | |
dict.push_back(make_pair("18","FR0010239111")); | |
dict.push_back(make_pair("42","FR0000186389")); | |
dict.push_back(make_pair("4C","FR0000186579")); | |
dict.push_back(make_pair("4C","FR0000186694")); | |
dict.push_back(make_pair("4C","FR0000187015")); | |
dict.push_back(make_pair("4C","FR0000187213")); | |
dict.push_back(make_pair("4C","FR0000187320")); | |
dict.push_back(make_pair("4C","FR0000187601")); | |
dict.push_back(make_pair("4C","FR0000187767")); | |
dict.push_back(make_pair("4C","FR0000187866")); | |
dict.push_back(make_pair("4C","FR0000188021")); | |
dict.push_back(make_pair("4C","FR0000188112")); | |
dict.push_back(make_pair("4C","FR0000188302")); | |
dict.push_back(make_pair("4C","FR0000188468")); | |
dict.push_back(make_pair("4D","FR0000186504")); | |
dict.push_back(make_pair("4D","FR0000187106")); | |
dict.push_back(make_pair("4D","FR0000583692")); | |
dict.push_back(make_pair("59","DE0005933956")); | |
sort(dict.begin(), dict.end()); | |
cout << "Full dictionary is:" << endl; | |
copy(dict.begin(), dict.end(), ostream_iterator<pair<string,string> > (cout, "\n") ); | |
cout << "stop" << endl; | |
cout << endl; | |
typedef vector<pair<string,string> >::const_iterator citer; | |
pair<citer, citer> range = equal_range(dict.begin(), dict.end(), make_pair("42", ""), key_comp); | |
cout << "42 values are:" << endl; | |
copy(range.first, range.second, ostream_iterator<pair<string,string> > (cout, "\n") ); | |
cout << "stop" << endl; | |
cout << "Distance is " << distance(range.first, range.second) << "." << endl; | |
cout << endl; | |
pair<citer, citer> values = equal_range(range.first, range.second, make_pair("", "FR0000186389"), val_comp); | |
cout << "(42, test2) are listed below when present:" << endl; | |
copy(values.first, values.second, ostream_iterator<pair<string,string> > (cout, "\n") ); | |
cout << "stop" << endl; | |
cout << "Distance is " << distance(values.first, values.second) << "." << endl; | |
values = equal_range(range.first, range.second, make_pair("", "test2"), val_comp); | |
cout << "(42, test2) are listed below when present:" << endl; | |
copy(values.first, values.second, ostream_iterator<pair<string,string> > (cout, "\n") ); | |
cout << "stop" << endl; | |
cout << "Distance is " << distance(values.first, values.second) << "." << endl; | |
range = equal_range(dict.begin(), dict.end(), make_pair("4C", ""), key_comp); | |
cout << "4C values are:" << endl; | |
copy(range.first, range.second, ostream_iterator<pair<string,string> > (cout, "\n") ); | |
cout << "stop" << endl; | |
cout << "Distance is " << distance(range.first, range.second) << "." << endl; | |
cout << endl; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment