Map - µÎ °³ÀÇ Å°·Î ã±â1

ÀÌÀü Àå¿¡¼­ Map - µÎ °³ÀÇ Å°·Î ã±â´Â ±¸Á¶Ã¼³ª Ŭ·¡½º¸¦ ¸¸µé¾î µÎ °³ÀÇ °ªÀ» ³Ñ°Ü ÁÖ°í, "opertor <" ¿¬»êÀÚ¸¦ ÅëÇؼ­ °ª ºñ±³¸¦ Çß´Ù.

À̹øÀå¿¡¼­´Â std::map< int, std::map< int, float > >¿Í °°ÀÌ mapÀ» ÀÌÂ÷¿ø ¹è¿­Ã³·³ »ç¿ë ÇÒ °ÍÀÌ´Ù.

ÄÚµå·Î ¼³¸íÀ» ´ë½Å ÇÑ´Ù.

typedef  std::map< int, std::map< int, float > > FloatTable;

 

void  main()

{

    StartDebug();

    FloatTable table;

 

    table[9][1] = 91.01f;

    //9,1 Å°ÀÇ °ªÀ» ¼öÁ¤

    table[9][1] = 91.77f;

#if  1

    table[3][7] = 37;

    table[3][5] = 35;

#else

    std::map< int, float > row3;

    row3.insert( std::make_pair( 7, 37.0f ) );

    row3.insert( std::make_pair( 5, 35.0f ) );

    table.insert( std::make_pair( 3, row3 ) );

 

#endif

 

    if( table.find(9) != table.end() && table[9].find(1) != table[9].end())

        std::cout << "table[9][1] = " << table[9][1] << std::endl;

 

    //3, 7 Å°ÀÇ °ªÀ» »èÁ¦

#if  1

    if( table.find(3) != table.end() && table[3].find(7) != table[3].end())

    {

        table[3].erase( 7 );  // ¶È°°Àº ¹® table[3].erase( table[3].find(7) );

        std::cout << "table[3][7] »èÁ¦" << std::endl;

    }

#else

    FloatTable::iterator iter =  table.find(3);

    if( iter != table.end() )

    {

        std::map< int, float >& map = iter->second;

        std::map< int, float >::iterator it = map.find( 7 );

        if( it != map.end() )

        {

            map.erase( it );

        }

    }

#endif

 

    if( table.find(3) != table.end() && table[3].find(7) != table[3].end())

        std::cout << "table[3][7] = " << table[3][7] << std::endl;

 

    if( table.find(3) != table.end() && table[3].find(5) != table[3].end())

        std::cout << "table[3][5] = " << table[3][5] << std::endl;

 

    fflush(stdout);

    _getch();

Á§Æ® : TwoKeyMap1.zip