0% found this document useful (0 votes)
6 views3 pages

2 Junior

The document contains problems and solutions from the American Computer Science League's 2018-2019 Junior Division Contest #2. It includes tasks related to prefix and infix notation evaluation, bit-string operations, and a program analysis. Each problem is followed by its corresponding solution, detailing the steps and final answers.

Uploaded by

forlooprange
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views3 pages

2 Junior

The document contains problems and solutions from the American Computer Science League's 2018-2019 Junior Division Contest #2. It includes tasks related to prefix and infix notation evaluation, bit-string operations, and a program analysis. Each problem is followed by its corresponding solution, detailing the steps and final answers.

Uploaded by

forlooprange
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

American Computer Science League

2018-2019 Contest #2
JUNIOR DIVISION

1. Pre/Post/Infix Notation 1.

Evaluate this prefix expression given all numbers are single digits.

+−/*2+354/9−↑221/+*35*62↑32

2. Pre/Post/Infix Notation 2.

Convert this infix expression to postfix.

3(a + 2 b) / (a2 − b/4) + a(ab + b2) / 2

3. Bit-String Flicking 3.

Evaluate the following:

10011 OR 01110 AND 10101

4. Bit-String Flicking 4.

Evaluate the following:

(LCIRC-2 01101) OR (RSHIFT-1 11111)


American Computer Science League
2018-2019 Contest #2
JUNIOR DIVISION

5. What Does This Program Do? - Loops 5.

What is the output when this program is executed?


a = 0: c = 0: t = 0
for i = 1 to 5
a=a+i↑2
next i
b = a / 11
for j = 2 to 10 step 2
c=c+j*b
next j
d = c / b − a / 11
for k = 2 to d
if a / k == int(a / k) then
t=t+1
end if
if b / k == int(b / k) then
t=t+1
end if
if c / k == int(c / k) then
t=t+1
end if
if d / k == int (d / k) then
t=t+1
end if
next k
output t
end
American Computer Science League
2018-2019 Contest #2
JUNIOR DIVISION SOLUTIONS

1. Pre/Post/Infix Notation 1. 4

+−/*2+354/9−↑221/+*35*62↑32
= + − / * 2 (+ 3 5) 4 / 9 − (↑ 2 2) 1 / + (* 3 5) (* 6 2) (↑ 3 2)
= + − / (* 2 8) 4 / 9 (− 4 1) / (+ 15 12) 9
= + − (/ 16 4) (/ 9 3) (/ 27 9)
= + (− 4 3) 3 = + 1 3 = 4

2. Pre/Post/Infix Notation 2. As shown

3(a + 2 b) / (a2 − b/4) + a(ab + b2) / 2


= 3 * (a + 2 * b) / (a ↑ 2 − b / 4) + a * (a * b + b ↑ 2) / 2
= 3 * (a + (2 b *)) / ((a 2 ↑) − (b 4 /)) + a * ((a b *) + (b 2 ↑)) / 2
= 3 * (a 2 b * +) / (a 2 ↑ b 4 / −) + a * (a b * b 2 ↑ +) / 2
= (3 a 2 b * + * a 2 ↑ b 4 / − /) + (a a b * b 2 ↑ + * 2 /)
=3a2b*+*a2↑b4/−/aab*b2↑+*2/+

3. Bit-String Flicking 3. 10111

10011 OR 01110 AND 10101 = 10011 OR (01110 AND 10101)


= 10011 OR 00100
= 10111

4. Bit-String Flicking 4. 11111

(LCIRC-2 01101) OR (RSHIFT-1 11111)


= 10101 OR 01111
= 11111

5. What Does This Program Do? - Loops 5. 12

The i loop gives the variable a values of 1, 5, 14, 30, 55 by adding the
squares. The j loop gives the variable c values of 10, 30, 60, 100, 150
by adding 5 times the value of j. Going into the k loop, a = 55, b = 5,
c = 150 and d = 25. This loop counts the factors of these numbers from
2 to 25. There are 12 factors. a : 5, 11 b: 5
c: 2, 3, 5, 6, 10, 15, 25 d: 5, 25

You might also like