jess_82
asked on
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.
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.
ASKER
Hello rock,
Would you please explain the algorithm a bit more? Would it give me that answer? Thanks.
Would you please explain the algorithm a bit more? Would it give me that answer? Thanks.
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?
what is the 3 3 at the start, does that represent the number of rows then columns?
ASKER
yes. Thanks.
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
'Current read info
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?
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
'Current read info
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?
ASKER
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.
My problem is not language. I am not seeing the answer. Do you see the answer? How do you decide the neighbor? Thanks.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I think this is it. Let me get the review this again. Thanks.
ASKER
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.
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.
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 (https://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
You could try asking a question in EE community support (https://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
> 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. ;-)
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. ;-)
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