Computer Science Canada

2008 junior CCC question #4

Author:  Horus [ Sat Dec 20, 2008 8:55 pm ]
Post subject:  2008 junior CCC question #4

so i was just looking at last year's question here:
http://cemc.math.uwaterloo.ca/contests/computing/2008/stage1/juniorEn.pdf

and i couldn't figure out what question #4 means.

i pretty much get polish notation but i don't understand how postfix notation works...

and btw does --3+219 means (-3)-(2+1+9) ?
just making sure...

Author:  jbking [ Sat Dec 20, 2008 10:06 pm ]
Post subject:  RE:2008 junior CCC question #4

Not quite....

Remember that - a b means a - b and - + a b c means a+b - c as the + a b is evaluated first and then that answer is used an input for the next operator.

- - 3 + 2 1 9

which equals :- - 3 (2+1) 9

which equals: - (3 - (2+1)) 9

which equals: 3 - (2+1) - 9 in infix notation which is different than you wrote.

Author:  Horus [ Sat Dec 20, 2008 10:16 pm ]
Post subject:  RE:2008 junior CCC question #4

oh ok, kinda get it now

but what about postfix notation?

Author:  OneOffDriveByPoster [ Sat Dec 20, 2008 10:49 pm ]
Post subject:  Re: RE:2008 junior CCC question #4

Horus @ Sat Dec 20, 2008 10:16 pm wrote:
oh ok, kinda get it now

but what about postfix notation?
Postfix is like how old calculators work:
3 2 -
means you are calculating (3 - 2); the calculation happens as soon as the operator (-) is used.

3 2 - 1 + would be (3 - 2) + 1.

3 2 - 1 9 * + would be (3 - 2) + (1 * 9).

Author:  Horus [ Sat Dec 20, 2008 10:54 pm ]
Post subject:  RE:2008 junior CCC question #4

ok thx i finally understand it now. now i can finally code haha.



lol if this type of question appears on CCC in 2009 i'm probably screwed...

Author:  Euphoracle [ Sun Dec 21, 2008 12:31 am ]
Post subject:  RE:2008 junior CCC question #4

When I did this, I was silly, and I converted it to our "regular" notation (in a sense), and then to the target format. I found it easier to work with a format I was comfortable with, and, although it wasn't the most efficient way of doing it, it got the job done correctly. I probably should have kept those solutions. Oh well.


: