• Status: Solved
• Priority: Medium
• Security: Public
• Views: 247

# Programming Problem

I am trying to solve this problem. I cannot seem to figure it out. I need to find the regional highest height from a subsection of a map. The regional highest height can be a point whose height is higher than all of its neighbors. The interior points have 8 neighbors, edge has 5 and corner has 3.

The input file is given below:
3 3
90 35°43'9" 45°45'19" 8 36°46'19" 51°25'19" 45 36°46'19" 11°25'39"
7 35°23'9" 25°43'9" 25 25°43'9" 35°33'39" 30 32°33'9" 17°33'22"
6 15°43'19" 25°43'29" 108 39°33'40" 25°23'29" 565 25°23'29" 15°41'19"

First number is the height, second is the longitude and third is the latitude. So For example, in the first record 90 is the height, 35°43'9" is the longitude and 45°45'19" is the latitude.

The answer is the maximum heights are 90, 45, 565. I am not sure how to come to this answer. I would really appreciate any help. Thanks.
0
jess_82
• 5
• 5
1 Solution

Commented:
what language?

I guess you would read each line and check for a common delimiter

e.g. VB, u can use the split command, split by spaces and this returns all elements in an array
you then there are 3 elements to one item i.e. height, long,lat

u have variables initialised to zero
u read each line one at a time

then compare current values with your variables. If higher,then assign your variables else continue to next

0

Author Commented:
Hello rock,
Would you please explain the algorithm a bit more? Would it give me that answer? Thanks.
0

Commented:
ok, I will do it in VB, is that okay?

what is the 3 3 at the start, does that represent the number of rows then columns?

0

Author Commented:
yes. Thanks.
0

Commented:
this is half VB, half comments

1) open text file for reading
2) read the first line, store in iNoRows and iNoCols - we can use this for validation of textfile, but assume at this moment everthing is fine

3) define and initialise variables

dim iHighestHeight as integer
dim sLong as String
dim sLat as String
dim sFlds() as String
dim i as integer
dim sLine as String

iHighestHeight=0
sLong = ""
sLat =""

4) now keep looping, read each record into array,

sLine - represents one line read

sFlds = Split(sLine, " ")
'unbound is last element subscript number in array
For i = 0 To UBound(sFlds) Step 3

Debug.Print "Height = " & sFlds(i)
Debug.Print "Long = " & sFlds(i + 1)
Debug.Print "Lat = " & sFlds(i + 2)

'Check height with last read highest height
If Val(sFlds(i)) > iHighestHeight Then
iHighestHeight = Val(sFlds(i))
sLong = sFlds(i + 1)
sLast = sFlds(i + 2)
End If
Next i

Now this only checks against the height, does it need to check against anything else?
0

Author Commented:
Hello Rock,
My problem is not language. I am not seeing the answer. Do you see the answer? How do you decide the neighbor? Thanks.
0

Commented:
Would you possibly define neighbour as one below, one to your right, one to your left and one on top?

e.g.

Line1                A1 LO1 LA1    A2 LO2 LA2    A3 LO3 LA3
Line2                B1 LO1 LA1    B2 LO2 LA2    B3 LO3 LA3
Line3                C1 LO1 LA1    C2 LO2 LA2    C3 LO3 LA3

If you take A1 LO1 LA1, its neighbours I presume would be A2 LO2 LA2 and B1 LO1 LA1 (possibly B2 as well if u go diagnally)

Similarly, B2 would have its neighbours as B1, B3, A2 and C2

does that make sense?

Lets put in the heights

90 35°43'9" 45°45'19" 8 36°46'19" 51°25'19" 45 36°46'19" 11°25'39"
7 35°23'9" 25°43'9" 25 25°43'9" 35°33'39" 30 32°33'9" 17°33'22"
6 15°43'19" 25°43'29" 108 39°33'40" 25°23'29" 565 25°23'29" 15°41'19"

Line1                90 LO1 LA1    8  LO2 LA2    45 LO3 LA3
Line2                7  LO1 LA1     25 LO2 LA2   30 LO3 LA3
Line3                6  LO1 LA1    108 LO2 LA2   565 LO3 LA3

So take 90, compare its neighbours, 8 and 7, 90 is highest
take 8, compare neighbours, and current highest height for this line, 90 is still highest and is highest neighbour
take 45, compare neighbours, 45 is highest, but highest recorded is still 90

and so on

do you think its something along those lines?

0

Author Commented:
I think this is it. Let me get the review this again. Thanks.
0

Author Commented:
Hello Rock,
Thanks so much. I think that is the answer. Is there any way I could set this question so that no one can view it or is not detected by a search? Thanks.
0

Commented:
I dont work for EE, Im just a volunteer expert  so Im afraid I cannot really help you here.
You could try asking a question in  EE community support (http://www.experts-exchange.com/Community_Support/),
Ive a feeling they will say no as its a response to a question, but if you have a valid reason, you could try though

Good luck

0

Commented:
> Is there any way I could set this question so that no one can view it or is not detected by a search?

Nope; all solutions are stored in the sites Knowledge Base - available to the public as well.

So, if (just for example here), your teacher or another student searched Google, then they may very well come across this question.  ;-)
0

## Featured Post

• 5
• 5
Tackle projects and never again get stuck behind a technical roadblock.