Starting from:

$30

CSE102-Assignment 8 Solved

•     Your program reads one text file:

–    input.txt

•     Your program creates a text file:

–    output.txt

•     Your program solves the following problem:

–    You are given a water level information L. Condition: 0<L<128.

–    You are given a terrain information (elevation matrix M). Condition: 0≤M[i][j]<128∀i,j<512.

–    Calculate how many islands are formed and return a coordinate value for each island.

–    Definition of an island: An island is the collection of terrain points( elevation values M[i][j]), above water( greater than L value), from which you can find a path to any other without having to pass the path through water.

–    Definition of a path: A path is an ordered set of points where successive points have either their X coordinates the same and their Y coordinates different only by one in magnitude (so can be y − 1 or y + 1); or have their Y coordinates the same and have their X coordinates different only by one in magnitude (so can be x − 1 or x + 1). But not both of them: in other words they have to touch either in the X direction or in the Y direction, and not in the diagonal.

–    If a piece of terrain is partially (or fully) located (touching) at the edge(s) of the 512 × 512 grid, still it will count as an island.

input.txt
•     First line is a single integer. (The L value)

•     The rest of the file has 262144 integers. Skip all the whitespace and read all of these integers and create a 512x512 matrix. Integers are listed in row-order.

output.txt
•     The first line is an integer (number of islands)

•     Each line after the first line holds coordinate information of a point on an island. (single point for each island)

•     Example: Here there are 5 islands. (#... are comments, which are not printed.)

5
 
x_coordinate1 y_coordinate1
#coordinate of a point which is on island1
x_coordinate2 y_coordinate2
#coordinate of a point which is on island2
x_coordinate3 y_coordinate3
#coordinate of a point which is on island3
x_coordinate4 y_coordinate4
#coordinate of a point which is on island4
x_coordinate5 y_coordinate5
#coordinate of a point which is on island5

More products