++



         

- 7


#include <vector>

#include <string>

#include <algorithm>

#include <iterator>

// <iostream>

#include <iostream.h>

class GreaterThan {

public:

GreaterThan( int size = 6 ) : _size( sz ){}

int size() { return _size; }

bool operator()(const string &s1)

{ return s1.size() > _size; }

private:

int _size;

};

class PrintElem {

public:

PrintElem( int lineLen = 8 )

: _line_length( lineLen ), _cnt( 0 )

{}

void operator()( const string &elem )

{

++_cnt;

if ( _cnt % _line_length == 0 )

{ cout << '\n'; }

cout << elem << " ";

}

private:

int _line_length;

int _cnt;

};

class LessThan {

public:

bool operator()( const string & s1,

const string & s2 )

{ return s1.size() < s2.size(); }

};

typedef vector<string, allocator> textwords;

void process_vocab( vector<textwords, allocator> *pvec )

{

if ( ! pvec ) {

//

return;

}

vector< string, allocator > texts;

vector<textwords, allocator>::iterator iter;

for ( iter = pvec->begin() ; iter != pvec->end(); ++iter )

copy( (*iter).begin(), (*iter).end(),

back_inserter( texts ));

// texts

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

// ,

for_each( texts.begin(), texts.end(), PrintElem() );

cout << "\n\n"; //

//

vector<string, allocator>::iterator it;

it = unique( texts.begin(), texts.end() );

texts.erase( it, texts.end() );

// ,

for_each( texts.begin(), texts.end(), PrintElem() );