ACCA Programming Contest

2007

Advanced – Exercise 1 - Skyline

Write a program which will take input of 4 tuples of (3) integers and output a skyline representing those tuples as buildings. One integer will represent the width of a building, one will represent the height and the third will represent the leftmost edge of the building.

The height of the tallest building must be no taller than 20 characters and no shorter than 2 characters. No building will be more than 12 characters wide and will be less than 3 characters wide. No building location can be larger than 40.

Buildings will be constructed of characters. The roof of each building will be a series of underscore characters (‘_’). The edges of the buildings will be a vertical series of pipe symbols (‘|’). The faces of the buildings will be a series of pound symbols (‘#’). The ground will be represented by a series of caret symbols (‘^’) starting at the location 1 and ending two characters after the last building. If any part of a building is hidden by another building it will not be displayed. In the far left column (column 0) number the lines from the line number mod 10. Beneath the ground repeat the series of digits from 1 to 0 as often as necessary to cover the last building. First defined buildings are in front, last in back.

======

Example input and output:

This program draws a skyline of buildings you define by height and width.

Please input the width of a building: 8

Please input the height of a building: 12

Please input the location of a building: 6

Please input the width of a building: 5

Please input the height of a building: 20

Please input the location of a building: 3

Please input the width of a building: 12

Please input the height of a building: 8

Please input the location of a building: 16

Please input the width of a building: 7

Please input the height of a building: 16

Please input the location of a building: 40

0 _____

9 |###|

8 |###|

7 |###|

6 |###| ______

5 |###| |#####|

4 |###| |#####|

3 |###| |#####|

2 |##______|#####|

1 |##|######| |#####|

0 |##|######| |#####|

9 |##|######| |#####|

8 |##|######| ______|#####|

7 |##|######| |##########| |#####|

6 |##|######| |##########| |#####|

5 |##|######| |##########| |#####|

4 |##|######| |##########| |#####|

3 |##|######| |##########| |#####|

2 |##|######| |##########| |#####|

1 |##|######| |##########| |#####|

^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

1234567890123456789012345678901234567890123456789012

ACCA Programming Contest

2007

Advanced – Exercise 2 – Primly Prime

A prime number is a positive integer greater than 1 that is divisible only by itself and by 1. So 2, 3, 5, 7, 11, 13, etc. are prime numbers. A lady named “Primly Prime” has numbers that she calls “primly primes.” These are integers, each digit of which is a prime. For example, 27 is a primly prime because both 2 and 7 are primes. 29 is a prime number by the usual definition, it is not a primly prime because 2 is a prime number, but 9 is not prime. 24 is neither a prime nor a primly prime.

Write a program which will explain the concept of “Primly Prime” and then prompt the user for an integer. Report to the user whether the integer given is:

  • Prime and primly prime
  • Not prime but primly prime
  • Prime but not primly prime
  • Neither prime nor primly prime

======

Example input and output:

A prime number is a positive integer greater than 1 that is divisible only by itself and by 1. So 2, 3, 5, 7, 11, 13, etc. are prime numbers. A lady named “Primly Prime” has numbers that she calls “primly primes.” These are integers, each digit of which is a prime. For example, 27 is a primly prime because both 2 and 7 are primes. 29 is a prime number by the usual definition, it is not a primly prime because 2 is a prime number, but 9 is not prime. 24 is neither a prime nor a primly prime.

This program allows you to input integers and find out whether they are: “Prime and primly prime”, “Not prime but primly prime”, “Prime but not primly prime”, or “Neither prime nor primly prime”

Please enter an integer (‘0’ to stop): 37

37Prime and primly prime

Please enter an integer (‘0’ to stop): 25

25Not prime but primly prime

Please enter an integer (‘0’ to stop): 43

43Prime but not primly prime

Please enter an integer (‘0’ to stop): 24

24Neither prime nor primly prime

Please enter an integer (‘0’ to stop): 0

Thanks for playing.

ACCA Programming Contest

2007

Advanced – Exercise 3 - Scrambler

Dudleyloves to play Scramble, the game in which you are given four letters and the winner identifies the most words of two or more letters that can be made from those four letters. The only problem is that Dudley is lazy. He doesn’t like to figure out all the words. But he’s also rich. He has offered you up to $5 to develop a program which will take four characters as input and will output all the permutations of characters of those four letters, in combinations of two, three or four letters

The permutations do not have to be in any particular order

======

Example input and output:

This program will output all the permutations for the four letters you input.

Please input a list of four letters:

satr

Those four letters can be rearranged to form the following sequences:

satr sart stra star srat srta

atrs atsr arst arts astr asrt

trsa tras tsar tsra tars tasr

rsat rsta rats rast rtsa rtas

sat sar srt sra str sta

atr ats asr ast ars art

trs tra tas tar tsa tsr

rsa rst rta rts rat ras

sa st sr

at ar as

tr ts ta

rs ra rt

ACCA Programming Contest

2007

Advanced – Exercise 4 – The Nohl Palindrome

A palindrome is a word or phrase that reads the same forward and backward. Examples of such palindromes are: “radar”, “Poor Dan is in a droop.”, “A man, a plan, a canal, Panama.”, and

“a Toyota”.

A Nohl palindrome is a palindrome of at least three characters in length embedded in a word, which itself is not a palindrome. Examples of words that are Nohl palindromes are: Mississippi, banana, robot, and institution. The embedded palindrome is in bold. Examples of words that are not Nohl palindromes are: radar, roof, table, and committee.

The order of a Nohl palindrome is the length of the palindrome substring.

Your task is to accept words on input and indicate whether or not the word is a Nohl palindrome. If it is a Nohl palindrome, you will further output the palindromic substring and its order. You must locate and output the Nohl palindrome with the largest order. See the examples below.

INPUT:Your program should accept a word with an appropriate prompt and continue to accept words until the string ‘***’ is entered. (Note: all words will be entered in lower case.)

OUTPUT:If the word is a Nohl palindrome, output YES followed by the palindromic substring and its order in the form:

YES: ppppppp: Order X

Otherwise, output NO.

EXAMPLE:Enter word: mississippi

YES: ississi: Order 7

Enter word: nincompoop

YES: poop: Order 4

Enter word: radar

NO

Enter word: robot

YES: obo: Order 3

Enter word: committee

NO

Enter word: ***

ACCA Programming Contest

2007

Advanced – Exercise 5 - Coordinates

Lester is a draftsman. He details designs developed by some high and mighty engineer. This engineer is so smart that he notes all locations of points on a plane with polar coordinates (r, θ (theta)). ‘r’ is the distance from the origin of a point P, and ‘θ’ is the angle from the positive x-axis to the line from the origin to point P.

Lester has discovered how to find the points in the x-axis and y-axis. The formulae are:

x = r cos(θ)and y = r sin(θ).

Lester’s lazy. He promises you $5 to develop a program that converts polar coordinates to rectangular coordinates. The program must prompt the user to input a pair of polar coordinates and then converts them to rectangular coordinates and outputs them to the screen. The values of the polar coordinates can be floating point decimals that represent units in length and angularity. The values of the rectangular coordinates must be floating point numbers with (3) two digits after the decimal point.

Example input and output:

======

This program calculates rectangular coordinates from polar coordinates.

Please input a length:6.0

Please input an angle:120.0

X = -3.000y = 5.196

Another < Y or N > y

Please input a length:8.75

Please input an angle:45.0

X = 6.187y = 6.187

Another < Y or N > N

Thanks and good-bye!

ACCA Programming Contest

2007

Advanced – Exercise 6 – Conveyor

Congratulations! You have completed college and entered the real world. You are now working for a manufacturing company.

Your boss wants you to develop a program to be used in conjunction with a material distribution system. The part that she wants you to program is a length of linear conveyor. The conveyor is long enough to hold 3 containers, but no more. When the third spot on the conveyor is occupied your program must set a system flag (to one) that tells the system not to delivery any more containers there. When a container is taken off the front of the conveyor gravity causes the remaining containers to roll forward and the last filled spot becomes vacant. If this is the third spot the system flag must be reset (to zero). For your purposes we’ll assume that gravity is full-proof in this regard.

Your job is to develop a program which takes container numbers as input (to simulate putting a container on the receiving end of the conveyor. If the third location is filled no input is allowed. After each input the program must identify the container numbers on each location of the conveyor. The program must also allow for the removal of containers from the exit end of the conveyor. If the third location has been filled and is now emptied input is allowed. After each removal the program must identify the container numbers on each location of the conveyor.

Example input and output:

======

Do you wish to input a container? <I> i

What container number? 123

Conveyor contents: 123 empty

Do you wish to input a container? <I>

Do you wish to remove a container? <R> i

What container number? 234

Conveyor contents: 123 234 empty

Do you wish to input a container? <I>

Do you wish to remove a container? <R> i

What container number? 345

Conveyor contents: 123 234 345 empty

Do you wish to input a container? <I>

Do you wish to remove a container? <R> i

What container number? 456

Conveyor contents: 123 234 345 456

Do you wish to remove a container? <R> r

You have removed container 123

Conveyor contents: 234 345 456 empty

Do you wish to input a container? <I>

Do you wish to remove a container? <R> X

Conveyor contents: 234 345 456 empty

Thanks and good-bye!