1992 (Niagara South)
Third Annual Niagara South Board
Programming CONTEST
February 1992
Teacher Instructions
1. Please duplicate enough copies of the tests for your students who are entering the competition.
2. The test is to be administered Thursday February 27, 1992 in the morning for a period of two and one half hours.
3. The team will consist of at most eight students.
3 students in their 4th or 5th year of secondary school
C. 3 students in their 3rd year of secondary school
C. 3 students in their 1st or 2nd year of secondary school
4. Students should have access to reference texts for the language they have chosen to use for the contest.
5. NO PRINTING may be used to help with debugging.
6. NO PREVIOUSLY CREATED files may be used as reference.
7. Please make sure the students save their solutions as indicated on their instructions.
8. Send the solutions disks and a cover page with the school name and all contestant names and years clearly indicated to marking committee before 3:30 February 28, 1992.
9. An entry fee of $2.00 per contestant should be brought to the March Computer Studies Council meeting.
Third Annual Niagara South Board
Programming CONTEST
February 1992
DO NOT TURN THIS PAGE UNTIL YOU ARE INSTRUCTED TO DO SO AND HAVE READ THE FOLLOWING CAREFULLY
1. YOU WILL HAVE TWO AND ONE-HALF HOURS FOR THIS CONTEST.
2. ALL SOLUTIONS ARE TO BE STORED ONTO THE DISKETTE GIVEN TO YOU BY THE PRESIDING TEACHER.
3. PRINTING IS NOT ALLOWED DURING THE CONTEST.
4. SOLUTIONS WILL BE JUDGED ON THE BASIS OF LOGICAL CORRECTNESS AND ALSO GOOD STRUCTURED STYLE, INPUT VALIDATION, AND SCREEN PRESENTATION.
5. YOU ARE TO ATTEMPT ONLY 2 QUESTIONS FROM PART A, 1 QUESTION ONLY FROM PART B AND 1 QUESTION ONLY FROM PART C.
6. IN DETERMINING YOUR OVERALL SCORE, THE 2 QUESTIONS FROM PART A ARE WORTH 25 POINTS EACH, THE 1 QUESTION FROM PART B IS WORTH 50 POINTS AND THE 1 QUESTION FROM PART C, 75 POINTS.
7. BY SUBMITTING ANY SOLUTION(S) TO ANY PROBLEM(S) IN THIS CONTEST YOU WILL HAVE GIVEN CONSENT TO THE NIAGARA SOUTH PROGRAMMING COMMITTEE TO USE YOUR SOLUTION IN ANY WAY.
PART A
DO 2 QUESTIONS FROM THIS PART
QUESTION A-1 [SAVE ON DISK AS "QA1" ]
The NSB Pizzeria sells take out pizza priced according to the chart below:
Write a program which simulates an automatic cash register. The input will be a two character code representing the size and number of extra toppings. The first character of the code will be an 'S', an 'M' or a 'L' representing small, medium and large. The second character of the code will be a digit 0 through 9 representing the number of extra toppings ordered. The output should show the basic cost of the pizza, the cost of the additional items, the total pizza cost, the GST calculated at 7%, the PST calculated at 8% and the TOTAL BILL.
QUESTION A-2 [SAVE ON DISK AS "QA2" ]
The Euclidean algorithm for finding the GCD (greatest common divisor) of two positive integers is to repeatedly replace the larger of the two numbers with the difference of the two numbers until the numbers become equal, at which point they are both equal to the desired GCD. Write a program which accepts two positive integers as input and gives the GCD as output.
QUESTION A-3 [SAVE ON DISK AS "QA3" ]
In the NHL, 2 points are awarded for each win, 1 point for each tie and 0 points are awarded for a loss. Write a program which accepts a list of 10 pairs of numbers representing the scores in the last 10 games played by the TORONTO MAPLE LEAFS as input. In each case, the first number represents the number of goals scored by the LEAFS and the second number represents the goals scored by the opposing team. The output should be a report showing the number of wins, the number of ties, the number of losses and the total number of points accumulated in the 10 games.
QUESTION A-4 [SAVE ON DISK AS "QA4" ]
Write a program which accepts any positive integer greater than 1 as an input. The output should be a list of all prime numbers which divide evenly into the input value. [NOTE: A prime number is a number which is divisible only by itself and 1.]
Example:
For the input 30, the output should be the numbers 2, 3 and 5.
PART B
DO ONLY 1 QUESTION FROM THIS PART
QUESTION B-1 [SAVE ON DISK AS "QB1" ]
Write a program which translates three ENGLISH words into PIG LATIN. The program should accept any three words entered without punctuation and output the PIG LATIN translation on one line, using the following rules to translate.
If the word contains any digits or hyphens, then the word does not change.
eg. The word "co-operation" remains unchanged.
Otherwise, if the word begins with a vowel, then concatenate "HAY" to the end
eg. The word "always" translates to the PIG LATIN "alwayshay"
Otherwise, if the word contains NO vowels, such as an anachronism, then append "AY" to it.
eg. The word "gst" becomes the PIG LATIN "gstay"
Otherwise, the frontmost consonant(s) are all to be removed and appended to the end of the word and followed by "AY".
eg. The word "storage" translates to the PIG LATIN "oragestay"
QUESTION B-2 [SAVE ON DISK AS "QB2" ]
Write a program which finds the MINIMUM value for Z where:
<image not available -- sorry!>
where A, B, and C can be any integer in the range L through H inclusive. The input to the program should be the range values L and H. The output should be the MINIMUM value found for Z, and the values of A, B and C which produced the minimum.
QUESTION B-3 [SAVE ON DISK AS "QB3" ]
Write a program which accepts the 2 fractions a/b and c/d as input. The values will actually be entered as four integers and assigned to the variables a, b, c and d. The output should be the fully reduced mixed fraction which results from adding a/b and c/d. This mixed fraction should be represented in the form of three integers, the first representing the whole number, the second representing the numerator of the fraction, and the third representing the denominator.
eg. for the fractions 3/4 and 1/2
INPUT the four values 3, 4, 1 and 2
OUTPUT the three values 1, 1, and 4 representing 1 1/4.
for the fractions 1/6 and 1/2
INPUT the four values 1, 6, 1 and 2
OUTPUT the three values 0, 2, and 3 representing 0 2/3
PART C
DO ONLY 1 QUESTION FROM THIS PART
QUESTION C-1 [SAVE ON DISK AS "QC1" ]
Write a program which generates a MAGIC SQUARE of order N. [NOTE: N MUST BE AN ODD NUMBER.] A MAGIC SQUARE of order N is an N by N matrix of integers where each row, each column and each diagonal sum to the same value. The input for this question should be the order of the MAGIC square (the value of N). The output should be the MAGIC SQUARE and the value found by adding all the values in the diagonal which runs from the top left to the bottom right. A method used for generating a magic square follows:
QUESTION C-1 Continued
de la Loubere's Method
Place a 1 in the top middle cell of the matrix. Subsequent numbers are placed in cells upward and to the right (go up, and then go over). When you leave the top of the square, reenter from the bottom remaining in the same column. When you leave the side of the square, reenter from the other side, remaining in the same row. If it is impossible to place the next number because the desired cell is occupied, place the next number directly below the most recent number.
eg. Magic Square - Order 3 Magic Square - Order 5
QUESTION C-2 [SAVE ON DISK AS "QC2" ]
Write a program which determines and reports the type of poker hand given any five cards. The possible values are defined in order (from highest to lowest) as follows:
ROYAL FLUSH: The Ace, King, Queen, Jack and Ten in the same suit
STRAIGHT FLUSH: any 5 cards of the same suit in numerical order
FOUR OF A KIND: 4 of the 5 cards have the same value
FULL HOUSE: 3 cards of the same value and two cards of the same value
STRAIGHT: 5 cards in the same order
THREE OF A KIND: 3 cards of the same value
TWO PAIR: 2 pairs of two cards of the same value
ONE PAIR: 1 pair of cards of the same value
GRUB: none of the above
The input is 5 two character codes representing the 5 cards. The first character is the VALUE of the card (2, 3, 4, 5, 6, 7, 8, 9, 0, J, Q, K, A NOTE THE TEN is represented with the character 0) followed by the character representing the suit (H, D, C, S representing Hearts, Diamonds, Clubs and Spades)
The output should be the highest possible value of the hand from the list above.
eg. INPUT 2H 2S 5D 6C 0C would generate the output "ONE PAIR".