#include <map>
struct monster
{
int Damage;
int PowerUp;
int Monster_Strength;
int hp;
int lvl;
int money;
int defense;
};
typedef std::pair<int,int> key ; // dungeon_level,moster_level pair
std::map< key, monster > look_up ;
#include <iostream>
std::ostream& operator << ( std::ostream& stm, const key& k )
{ return stm << '(' << k.first << ',' << k.second << ')' ; }
std::ostream& operator << ( std::ostream& stm, const monster& m )
{
return stm << "monster{" << m.Damage << ',' << m.PowerUp << ',' << m.Monster_Strength
<< ',' << m.hp << ',' << m.lvl << ',' << m.money << ',' << m.money << '}' ;
}
int main()
{
// initialize look_up
{
monster m11 = { 23, 2, 5, 8, 19, 7, 9 } ; /* monster 1,1*/
look_up[ key(1,1) ] = m11 ;
monster m12 = { 5, 7, 15, 2, 8, 15, 6 } ; /* monster 1,2*/
look_up[ key(1,2) ] = m12 ;
monster m35 = { 1, 3, 11, 9, 17, 6, 1 } ; /* monster 3,5*/
look_up[ key(3,5) ] = m35 ;
}
key k( 1, 2 ) ;
std::cout << k << '\n' ;
typedef std::map< key, monster >::iterator iterator_t ;
for( iterator_t iter = look_up.begin() ; iter != look_up.end() ; ++iter )
std::cout << "key: " << iter->first << " => data: " << iter->second << '\n' ;
}
I2luY2x1ZGUgPG1hcD4KCnN0cnVjdCBtb25zdGVyCnsKICAgIGludCBEYW1hZ2U7CiAgICBpbnQgUG93ZXJVcDsKICAgIGludCBNb25zdGVyX1N0cmVuZ3RoOwogICAgaW50IGhwOwogICAgaW50IGx2bDsKICAgIGludCBtb25leTsKICAgIGludCBkZWZlbnNlOwp9OwoKdHlwZWRlZiBzdGQ6OnBhaXI8aW50LGludD4ga2V5IDsgLy8gZHVuZ2Vvbl9sZXZlbCxtb3N0ZXJfbGV2ZWwgcGFpcgoKc3RkOjptYXA8IGtleSwgbW9uc3RlciA+IGxvb2tfdXAgOwojaW5jbHVkZSA8aW9zdHJlYW0+CgpzdGQ6Om9zdHJlYW0mIG9wZXJhdG9yIDw8ICggc3RkOjpvc3RyZWFtJiBzdG0sIGNvb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X3QgaXRlciA9IGxvb2tfdXAuYmVnaW4oKSA7IGl0ZXIgIT0gbG9va191cC5lbmQoKSA7ICsraXRlciApCgkgICAgc3RkOjpjb3V0IDw8ICJrZXk6ICIgPDwgaXRlci0+Zmlyc3QgPDwgIiA9PiBkYXRhOiAiIDw8IGl0ZXItPnNlY29uZCA8PCAnXG4nIDsKfQo=
(1,2)
key: (1,1) => data: monster{23,2,5,8,19,7,7}
key: (1,2) => data: monster{5,7,15,2,8,15,15}
key: (3,5) => data: monster{1,3,11,9,17,6,6}