fork download
  1. #include <map>
  2.  
  3. struct monster
  4. {
  5. int Damage;
  6. int PowerUp;
  7. int Monster_Strength;
  8. int hp;
  9. int lvl;
  10. int money;
  11. int defense;
  12. };
  13.  
  14. typedef std::pair<int,int> key ; // dungeon_level,moster_level pair
  15.  
  16. std::map< key, monster > look_up ;
  17. #include <iostream>
  18.  
  19. std::ostream& operator << ( std::ostream& stm, const key& k )
  20. { return stm << '(' << k.first << ',' << k.second << ')' ; }
  21.  
  22. std::ostream& operator << ( std::ostream& stm, const monster& m )
  23. {
  24. return stm << "monster{" << m.Damage << ',' << m.PowerUp << ',' << m.Monster_Strength
  25. << ',' << m.hp << ',' << m.lvl << ',' << m.money << ',' << m.money << '}' ;
  26. }
  27.  
  28. int main()
  29. {
  30. // initialize look_up
  31. {
  32. monster m11 = { 23, 2, 5, 8, 19, 7, 9 } ; /* monster 1,1*/
  33. look_up[ key(1,1) ] = m11 ;
  34.  
  35. monster m12 = { 5, 7, 15, 2, 8, 15, 6 } ; /* monster 1,2*/
  36. look_up[ key(1,2) ] = m12 ;
  37.  
  38. monster m35 = { 1, 3, 11, 9, 17, 6, 1 } ; /* monster 3,5*/
  39. look_up[ key(3,5) ] = m35 ;
  40. }
  41.  
  42. key k( 1, 2 ) ;
  43. std::cout << k << '\n' ;
  44.  
  45. typedef std::map< key, monster >::iterator iterator_t ;
  46. for( iterator_t iter = look_up.begin() ; iter != look_up.end() ; ++iter )
  47. std::cout << "key: " << iter->first << " => data: " << iter->second << '\n' ;
  48. }
  49.  
Success #stdin #stdout 0s 2820KB
stdin
Standard input is empty
stdout
(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}