Ticker

6/recent/ticker-posts

Header Ads Widget

Responsive Advertisement

Continents and Oceans


There will be several continents on a world map. Idea is to identify the number of continents and the mass in each.

The land is denoted by ‘#’ and ocean by spaces. You have to find the number of continents (connected masses of land) and print the number of # in the continent.

Connected mass of land means that # can be connected in any way i.e. horizontally, vertically or diagonally.

Input Format:

  1. Path to a file, for example /tmp/T1.txt
  2. This file contains 15 rows and 60 columns depicting a map. See Examples section below.

Output Format:

Number of # per continent in descending order of size and total number of continents in the format depicted below

Island 1: <Biggest mass> say 100
Island 2: <Smallest mass> say 50
Number of continents: 2

Example 1:

Output:
Island 1: 593
Island 2: 98
Number of continents: 2

So Output is:
Island 1: 593
Island 2: 98
Number of continents: 2

Example 2:

Output:
Island 1: 805
Island 2: 68
Number of continents: 2

Post a Comment

0 Comments