• Create Account

### #ActualMichael Tanczos

Posted 29 December 2012 - 01:20 AM


#include <algorithm>
#include <iostream>
#include <iterator>
#include <string>
#include <vector>
#include <utility>

using namespace std;

typedef pair<int,string> Pair;

inline bool less_than_second( const Pair& b1, const Pair& b2 ){
return b1.second < b2.second;
}

int main( )
{
const char* names[] = { "A","B", "C", "D","E" };
const int values[] = { 18, 20, 26, 30, 41 };
const int num_pairs = sizeof( names ) / sizeof( names[0] );

vector<Pair> pair( num_pairs );
transform( values, values+num_pairs, names,pair.begin(), make_pair<int,string> );

sort( pair.begin(), pair.end() );

using namespace std;

typedef pair<int,string> Pair;

inline bool less_than_second( const Pair& b1, const Pair& b2 ){
return b1.second < b2.second;

}


### #7Michael Tanczos

Posted 29 December 2012 - 01:11 AM


#include <algorithm>
#include <iostream>
#include <iterator>
#include <string>
#include <vector>
#include <utility>

using namespace std;

typedef pair<int,string> Pair;

inline bool less_than_second( const Pair& b1, const Pair& b2 ){
return b1.second < b2.second;
}

int main( )
{
const char* names[] = { "A","B", "C", "D","E" };
const int values[] = { 18, 20, 26, 30, 41 };
const int num_pairs = sizeof( names ) / sizeof( names[0] );

vector<Pair> pair( num_pairs );
transform( values, values+num_pairs, names,pair.begin(), make_pair<int,string> );

sort( pair.begin(), pair.end() );

sort( pair.begin(), pair.end(), less_than_second );

vector<Pair>::const_iterator pair_end = pair.end();
for( vector<Pair>::const_iterator i = pair.begin();
i != pair_end; ++i )
<div>}</div>
<div>

### #5Michael Tanczos

Posted 29 December 2012 - 01:09 AM

#include <algorithm>
#include <iostream>
#include <iterator>
#include <string>
#include <vector>
#include <utility>

using namespace std;

typedef pair<int,string> Pair;

inline bool less_than_second( const Pair& b1, const Pair& b2 ){
return b1.second < b2.second;
}

int main( )
{
const char* names[] = { "A","B", "C", "D","E" };
const int values[] = { 18, 20, 26, 30, 41 };
const int num_pairs = sizeof( names ) / sizeof( names[0] );

vector<Pair> pair( num_pairs );
transform( values, values+num_pairs, names,pair.begin(), make_pair<int,string> );

sort( pair.begin(), pair.end() );

sort( pair.begin(), pair.end(), less_than_second );

vector<Pair>::const_iterator pair_end = pair.end();
for( vector<Pair>::const_iterator i = pair.begin();
i != pair_end; ++i )
}

PARTNERS