#include <fstream>
#include <sstream>
void foo( pair<string, list<int> > p )
{
        cout << p.first << endl;
}
void main()
{
        map<string, list<int> > cross_index; // 이 자료구조를 생각해보자.
        //map<string, list<list<int> > >;    // 2차원 배열도 받아서 할 수 있다.
        ifstream f("a.cpp");   // 현재 파일이름 넣으세요.
        int line = 0;          // line no 관리
        string temp;
        // file에서 한 줄씩 읽어 들인다.
        while( getline( f, temp ) )     // 주의 f >> temp; 한 단어 입력
        {
               ++line; // 라인 no++
               istringstream iss( temp );
               string word;
               while( iss >> word )          // 한 문장을 단어별로 분리해 낸다.
               {
                       cross_index[ word ].push_back(line);
               }
        }
        //------------------------------------
        // 이제 map을 출력한다.
        // print_word_list
        for_each( cross_index.begin(), cross_index.end(), foo );
        // print_word_line_list
        map<string, list<int> >::iterator p = cross_index.begin();
        
        ostream_iterator<int> out( cout, " " );
        while ( p != cross_index.end() )
        {
               cout << p->first << " : "; // 단어출력
               copy( p->second.begin(), p->second.end(), out );
               cout << endl;
               ++p;
        }
}
// 응용비디오샵!!!
//map<Customer, list<VideoTape> > retal_list
//copy( cross_index["홍길동"].begin(), cross_index["홍길동"].end(), out );