UNSW Compucon Programming Competition 1998
Preliminary Round, Junior Section

Advice to Competitors

At the start of the competition you should receive a copy of the description of the tasks that the team may attempt over the available two hours. For the Junior Section, four tasks have been set; for the Open Section, six tasks. If any Junior team completes all four tasks to the satisfaction of the supervisor, they are welcome to attempt one or more Open tasks (start with Task Open/A).

We have provided a range of problems of varying difficulty: we expect that very few teams will be able to complete all, or even most of the tasks. Do not be discouraged if you don't get many of them done. There is no pass mark, and points are given to indicate our estimates of their relative difficulty. Even solving one problem is an achievement.

The computer you will use should by now contain a directory UNSWPC98 in which you will find separate directories OpenA, OpenB, and so on to OpenF, and JnrA to JnrD. (If they haven't been installed, copy and unzip the file UNSWPC98.ZIP found on your supervisor's competition disk). These directories contain test files with which to exercise your programs. In particular, files of the form Test1.dat, Test2.dat store input data for the program you will write. To establish how well your program works you need to print a copy of the program output for each of these files. Your supervisor will also ask you at the end of the time period to print program listings for each task at least partially completed.

Because you have to share a single computer you may that find the best strategy is to work on two or three tasks simultaneously (one or two people on each task). The programs should be clearly written and neatly formatted. Do not worry about fancy user interaction: all input will come from a test file. The printed copy of each test run can either be a printed text file or a screen dump.

Good luck. No doubt you will find the competition challenging, but hopefully also rewarding.

Summary of Tasks

Junior Section Open Section
Task Title Title Points (basic) Points (max)
A Odd Sums Barcode Validation 5 8
B PIN Security Matching Suffixes 8 12
C Chessboard Generator Pascal's Triangle 12 12
D Word Length Integer Substrings 8 15
E (Not applicable) Square Root Calculator 10 10
F (Not applicable) Rotation Cipher 15 15

There are no points score or extensions for tasks in the Junior Section. Certificates will be issued based on the number of tasks successfully completed. Some of the tasks in the Open Section have extensions, so a range of points is possible.

Task A: Odd Sums

Description

For any of you who haven't seen the result described here, the output of your program (provided it's correctly written of course) may be surprising. For that reason, we haven't produced complete input/output examples.

Write a program that produces a table containing numbers printed in three columns and several rows.

The program should stop after the 15th row is displayed.

Sample output

   1    1    1  
   2    3    4
   3    5    ?
   4    7    ?
   5    9    ?
   6   11    ?
   7   13    ?
   . . .

Constraints

None.

Task B: PIN Security

Description

PINs (Personal Identification Numbers) are typically 4 to 6-digit numbers associated with a credit or debit card. Users are warned not to write down their PIN unless it's in coded form. One common code (which means that it's not very secure!) is easy to calculate, even mentally. It replaces each digit by that digit's nine's complement. The nine's complement of any digit d is the value 9-d. Write a program that reads in one or more PINs and displays each PIN and its coded equivalent. The input ends with a line containing just a single 0.

Try to make the program as general as possible: accept PINs of any length up to, say, 20 digits; accept any number of PINs and process each one as you read it. If this is too ambitious, then at least get your program to read one 4-digit PIN and display its code.

Sample Input/output

Input Output
1234
909090
11111
7920
0
1234 = 8765
909090 = 090909
55555 = 44444
7920 = 2079
   

Constraints

None.

Task C: Chessboard Generator

Description

Write a program that draws a chessboard pattern of any specified size using single characters for each square. The input to the program is on three lines: Use the square colouring convention adopted for chessboards: the top left-hand corner is a light-coloured square.

Sample Input/output

Input Output Input Output
8
*
    
 * * * * * * * *
* * * * * * * * 
 * * * * * * * *
* * * * * * * * 
 * * * * * * * *
* * * * * * * * 
 * * * * * * * *
* * * * * * * * 
6
#
.  
.#.#.#.#.#.#
#.#.#.#.#.#.
.#.#.#.#.#.#
#.#.#.#.#.#.
.#.#.#.#.#.#
#.#.#.#.#.#.

Input Output Input Output Input Output
3
+
-  
-+-
+-+
-+-
2
1
0  
01
10
1
X
0  
0

Constraints

Square size is not less than 1 nor greater than 80. Accept the first character on the second and third lines: ignore any other input characters.

Task D: Word Length

Description

Write a program that finds the longest word on each line of its input. The input file contains any number of lines of text. The text consists of "words", which are defined here as consisting of any characters except a space, and could be separated by one or more spaces. For each line that contains one or more words, display the word with the largest number of characters.

If there are two or more words with maximum length on the line, display only the first such word.

Sample Input/output

Input Output
The Emperor's New Clothes
Cinderella

three blind mice
see how they run
Emperor's
Cinderella
three
they
   

Constraints

Lines will not be greater than 80 characters in length. A word could be as short as one character or as long as the line. There could be as many as 40 words on each line.