Jump to content

  • Log In with Google      Sign In   
  • Create Account

#ActualMichael Tanczos

Posted 29 December 2012 - 01:04 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 )
   cout << i->second << " - $" << i->first << " values\n";
}
 
 

#8Michael Tanczos

Posted 29 December 2012 - 12:38 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 )
   cout << i->second << " - $" << i->first << " values\n";
}
 
 

#7Michael Tanczos

Posted 29 December 2012 - 12:38 AM

 
#include <algorithm>
#include <iostream>
#include <iterator>
#include <string>
#include <vector>
#include <utility>
[b]This is bold[/b]
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 )
   cout << i->second << " - $" << i->first << " values\n";
}
 
 

#6Michael Tanczos

Posted 29 December 2012 - 12:33 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 )
   cout << i->second << " - $" << i->first << " values\n";
}
 
 

#5Michael Tanczos

Posted 29 December 2012 - 12:30 AM

 
</p><div>#include <algorithm></div>
<div>#include <iostream></div>
<div>#include <iterator></div>
<div>#include <string></div>
<div>#include <vector></div>
<div>#include <utility></div>
<div> </div>
<div>using namespace std;</div>
<div> </div>
<div>typedef pair<int,string> Pair;</div>
<div> </div>
<div>inline bool less_than_second( const Pair& b1, const Pair& b2 ){</div>
<div>   return b1.second < b2.second;</div>
<div>}</div>
<div> </div>
<div>int main( )</div>
<div>{</div>
<div>   const char* names[] = { "A","B", "C", "D","E" };</div>
<div>   const int values[] = { 18, 20, 26, 30, 41 };</div>
<div>   const int num_pairs = sizeof( names ) / sizeof( names[0] );</div>
<div> </div>
<div>   vector<Pair> pair( num_pairs );</div>
<div>   transform( values, values+num_pairs, names,pair.begin(), make_pair<int,string> );</div>
<div> </div>
<div>   sort( pair.begin(), pair.end() );</div>
<div> </div>
<div>   sort( pair.begin(), pair.end(), less_than_second );</div>
<div> </div>
<div>   vector<Pair>::const_iterator pair_end = pair.end();</div>
<div>   for( vector<Pair>::const_iterator i = pair.begin();</div>
<div>      i != pair_end; ++i )</div>
<div>   cout << i->second << " - $" << i->first << " values\n";</div>
<div>}</div>
<div>
 
 

#4Michael Tanczos

Posted 29 December 2012 - 12:28 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 )
   cout << i->second << " - $" << i->first << " values\n";
}

PARTNERS