Solved

# Programming Problem

Posted on 2006-05-22
201 Views
Last Modified: 2010-04-17
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
Question by:jess_82
11 Comments

LVL 65

Expert Comment

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 Comment

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

LVL 65

Expert Comment

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 Comment

yes. Thanks.
0

LVL 65

Expert Comment

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?
0

Author Comment

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

LVL 65

Accepted Solution

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 Comment

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

Author Comment

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

LVL 65

Expert Comment

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

LVL 25

Expert Comment

> 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

## Write Comment

Please enter a first name

Please enter a last name

We will never share this with anyone.

## Featured Post

I know it’s not a new topic to discuss and it has lots of online contents already available over the net. But Then I thought it would be useful to this site’s visitors and can have online repository on vim most commonly used commands. This post h…
A short article about a problem I had getting the GPS LocationListener working.
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

#### 779 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

#### Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!