#ifndef __COLOR_MAP__ #define __COLOR_MAP__ #include enum theColors {red, blue, green, yellow, none}; const int MAX_MAP_SIZE = 10; class color { private: theColors hue; public: color() { hue = none; } color(theColors x) { hue = x; } bool operator == (theColors c) { return (hue == c); } bool operator == (color h) { return (hue == h.hue); } color& operator = (theColors c) { hue = c; return *this; } color operator++() { hue = (theColors)((int)hue + 1); return color((theColors)((int)hue + 1)); } friend std::ostream& operator<< (std::ostream& out, color c); }; std::ostream& operator<< (std::ostream& out, color c) { switch (c.hue) { case red: out << "red "; break; case blue: out << "blue "; break; case green: out << "green "; break; case yellow: out << "yellow "; break; case none: out << "none "; }; return out; } class map { private: int numOfCountries; bool neighbor[MAX_MAP_SIZE][MAX_MAP_SIZE]; color coloring[MAX_MAP_SIZE]; public: map() { numOfCountries = 0; for (int i = 0; i < MAX_MAP_SIZE; i++) for (int j = 0; j < MAX_MAP_SIZE; j++) neighbor[i][j] = false; for (int i = 0; i < MAX_MAP_SIZE; i++) coloring[i] = color(none); } bool isValidColoring(int country, color h); void colorCountry(int country, color h) { coloring[country] = h; } friend std::istream& operator>>(std::istream& in, map& world); friend std::ostream& operator<<(std::ostream& out, map& world); friend bool ColorMap(int country, map& world); }; std::istream& operator>>(std::istream& in, map& world) { in >> world.numOfCountries; int tmp; for (int i = 0; i < world.numOfCountries; i++) for (int j = 0; j < world.numOfCountries; j++) { in >> tmp; if (tmp == 1) world.neighbor[i][j] = true; else world.neighbor[i][j] = false; } for (int i = 0; i < MAX_MAP_SIZE; i++) world.coloring[i] = color(none); return in; } std::ostream& operator<<(std::ostream& out, map& world) { for (int i = 0; i < world.numOfCountries; i++) { out << "Country " << i << ": " << world.coloring[i] << std::endl; } return out; } bool map::isValidColoring(int country, color h) { for (int i = 0; i < numOfCountries; i++) { if (neighbor[i][country] == true) { if (coloring[i] == h) return false; } } return true; } #endif