fork(2) download
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 

using namespace std;

typedef std::pair cell;

enum island_status {COMPLETE,INCOMPLETE};
enum color {WHITE = -2, BLACK = -1 };

class island
{
public:
	std::set cells;
	island_status status;
};
class nurikabe
{
	std::vector> grid;
	std::map islands;
	unsigned int l1,l2;	
	void color_black(cell);
public:
	nurikabe();
	nurikabe(std::string);
	void solve();
	void print();
	void find_islands();
	unsigned int any_complete_island();
	int fill_adjacent(cell);
};



void nurikabe::solve()
{
	find_islands();
	unsigned int i = 0;
	do
	{
		i = 0;
		i += any_complete_island();
		cout< 0)
				{
					islands[grid[i][j]] = new island;
					islands[grid[i][j]]->status = INCOMPLETE;
					islands[grid[i][j]]->cells.insert(make_pair(i,j));
			}
		}
	}
}
unsigned int nurikabe::any_complete_island()
{
	int i =0;
	auto it = islands.cbegin();
	auto end = islands.cend();
	for( ;it != end ; ++it)
	{
		auto & an_island = (*it).second;
		if( an_island->status == INCOMPLETE && (*it).first == an_island->cells.size() )
		{
			++i;
			an_island->status = COMPLETE;
			for_each(an_island->cells.cbegin(),an_island->cells.cend(),std::bind(&nurikabe::fill_adjacent,this));
		}
	};
	return i;
}

int nurikabe::fill_adjacent(cell c)
{
	color_black(make_pair(c.first,c.second+1));
	color_black(make_pair(c.first+1,c.second));
	color_black(make_pair(c.first,c.second-1));
	color_black(make_pair(c.first-1,c.second));

	return 0;
}

void nurikabe::color_black(cell c)
{
	if(grid[c.first][c.second] != WHITE)
		grid[c.first][c.second] = BLACK;
}
nurikabe::nurikabe(string filename)
{
	fstream input (filename);
	string aline;
	
	unsigned int size =0;
	while(input)
	{
		getline(input,aline);
		if(aline.size() > 0)
		{
			istringstream line(aline);
			istream_iterator begin(line), end;
			grid.push_back(vector(begin,end));
		}
	}
	l2 = grid[0].size();
	l1 = grid.size();
}

void nurikabe::print()
{
	//print out the puzzle
	for( auto i = grid.cbegin();i != grid.cend();i++)
	{
		cout<
				
				
				
				
				
				
			
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
In file included from /usr/lib/gcc/i686-pc-linux-gnu/4.5.1/../../../../include/c++/4.5.1/algorithm:63:0,
                 from prog.cpp:10:
/usr/lib/gcc/i686-pc-linux-gnu/4.5.1/../../../../include/c++/4.5.1/bits/stl_algo.h: In function '_Funct std::for_each(_IIter, _IIter, _Funct) [with _IIter = std::_Rb_tree_const_iterator<std::pair<int, int> >, _Funct = std::_Bind<std::_Mem_fn<int (nurikabe::*)(std::pair<int, int>)>(nurikabe*)>]':
prog.cpp:85:103:   instantiated from here
/usr/lib/gcc/i686-pc-linux-gnu/4.5.1/../../../../include/c++/4.5.1/bits/stl_algo.h:4185:2: error: no match for call to '(std::_Bind<std::_Mem_fn<int (nurikabe::*)(std::pair<int, int>)>(nurikabe*)>) (const std::pair<int, int>&)'
stdout

Standard output is empty