Round 1 Problems
These problems were made available both here and on
Computimes
(in the Irish
Times) on Monday 29th of January. They were also sent to all schools in Ireland
on the same day.
1. Maximin
Write a program that will find the maximum and the minimum of a list
of positive numbers.
Example
How many numbers ? 8
4 2 7 23 10 9 19 5
The maximum is 23, the minimum is 2.
2. Egg Timer
Write a program that will ask the user for a whole number N between 3
and 10 and print an egg timer of size N.
Example
Enter a number ? 4
*-*-*-*
*-*-*
*-*
*
*-*
*-*-*
*-*-*-*
3. Remainder
You are given two words, and your job is to remove all letters from the
first word that are contained in the second. For example, if you are given the
words computer program, remove letters from the word
computer if they occur in program, leaving the
letters cute.
Example
Enter two words : computer program
Remainder : cute
4. Encryption
A secret code reorders the letters in a message using an array. E.g. the
following message
Attack at dawn or we are done for is placed in a 6*6 array
:
Attack
*at*da
wn*or*
we*are
*done*
for...
Blanks are replaced by asterisks, and full stops are added to the message
so that it fills out the array. The coded message is obtained by reading down
the columns, i.e.
A*ww*ftanedott**ora*oan.cdrre.ka*e*.
Write a program that will encode a message as above. Use an array with
6 columns, and adjust the number of rows depending on the message
length.
Example
Enter a message : Attack at dawn or we are done for
The encrypted message is : A*ww*ftanedott**ora*oan.cdrre.ka*e*.
For extra marks, write a program to decode a message that has been
encrypted using the above rules.
5. Come to Nothing
Consider the sequence of digits from 1 through N (where N <= 9) in
increasing order:
1 2 3 4 5 ....N
Insert either a + (for addition) or a - (for subtraction) between each of the
digits so that the resultant sum is zero.
Print all possible combinations that sum to zero.
Example
Enter a number ? 7
1 + 2 - 3 + 4 - 5 - 6 + 7 = 0
1 + 2 - 3 - 4 + 5 + 6 - 7 = 0
1 - 2 + 3 + 4 - 5 + 6 - 7 = 0
1 - 2 - 3 - 4 - 5 + 6 + 7 = 0