int main(int argc, const char * argv[]) { // insert code here... std::cout << "How many islands in this mpa?\n"; std::vector< std::vector<bool> > map; for ( int i = 1; i < argc; i++) { //for each row std::string s( argv[i] ); std::cout << s << "\n"; std::vector< bool > row; for ( int j = 0; j < s.length(); j++ ) { if (s[j] == '1') row.push_back(true); else row.push_back(false); } map.push_back(row); } int i = countIslands(map); std::cout << "found " << i << " islands.\n"; return 0; }
int main(){ int M[][N]= { {1, 1, 0, 0, 0}, {0, 1, 0, 0, 1}, {1, 0, 0, 1, 1}, {0, 0, 0, 0, 0}, {1, 0, 1, 0, 1} }; printf("Number of islands is: %d\n", countIslands(M)); return 0; }
int main() { srand(time(0)); bool world[HEIGHT][WIDTH]; for (int row = 0; row < HEIGHT; ++row) { for (int col = 0; col < WIDTH; ++col) { world[row][col] = rand() % 2; } } print(world); auto n = countIslands(world); std::cout << "# islands: " << n << "\n"; return 0; }