gt5163b@prism.gatech.edu (Brian McNamara!) once said: >Write a program which will accept a haiku as input and create a >line-index based off each word in the haiku. For example, given the >input: > > c++ is the > favorite extant language > of the brian mac > >the output should be > > of the brian mac > c++ is the > favorite extant language > favorite extant language > c++ is the > favorite extant language > of the brian mac > of the brian mac > c++ is the > of the brian mac Here's my solution (commentary to follow): #include #include #include #include typedef pair Index; struct Cmp : public binary_function { bool operator()( const Index& x, const Index& y ) const { return lexicographical_compare(x.first.begin()+x.second,x.first.end(), y.first.begin()+y.second,y.first.end()); } }; typedef set Set; unsigned int N = 0; void insert( Set& s, const string& x ) { string::const_iterator i = x.begin(); for(;;) { i = find_if( i, x.end(), bind1st(not_equal_to(),' ') ); if( i == x.end() ) break; unsigned int len = i - x.begin(); N = max( len, N ); s.insert( make_pair(x,len) ); i = find_if( i, x.end(), bind1st(equal_to(),' ') ); } } void print( const Index& x, unsigned int n ) { for( unsigned int i=0; i