Round 1 Problems

1. Factorials

The factorial of an integer n, written n!, is the product of all the integers from 1 to n inclusive. For example, 5! = 1 * 2 * 3 * 4 * 5 = 120. Write a program that accepts a number, n (1 < = n < = 12), as input and prints the factorial of that number.

Example

	Enter a Number : 4
	4! = 24

Test your program with the following numbers : 1, 4, 6, 10, 12.

2. Is this a Triangle

Your job is to classify a triangle based on the lengths of its sides. Write a program to take three numbers, a, b and c, which are the lengths of the sides of a triangle, and classify the triangle as isosceles, equilateral, possible or impossible.

Note that an isosceles triangle has two equal sides, an equilateral triangle has three equal sides, an impossible triangle cannot be formed from the three sides (e.g. a = 1, b = 2, and c = 5) and a possible triangle is everything else.

Example

	Enter three sides : 2 4 3
	possible

Test your program with the following sides

	2 2 2
	1 2 5
	1 1 2
	2 3 4

3. Common Letters

Write a program that takes two words and finds any common letters that they have. For example, the words ‘computer’ and ‘program’ have the letters ‘o’, ‘m’, ‘p’, ‘r’ in common. The output should be both words with all common letters in capitals. Neither word will have more than 8 letters.

Example

	Enter two words : computer program
	cOMPuteR PROgRaM

Test your program with the following pairs of words

	hello all
	bye all

4. Word Chain

A word chain is a daisy chain made from words. Two words, w1 and w2, may be linked if the last letter of w1 is the same as the first of w2. E.g. ‘bar’ and ‘red’ may be linked. You must form a word-chain from a list of words that you are given. The word-chain must No word may be used more than once.

Input

The input will be a list of N words. The first item will be N, (4 < = N < = 25), followed by the list of words. No word will have more than 8 letters.

Output

Will be a list of four words that form a chain.

Example

	Enter the list of words : 5
	gap pet big tab tar
	A four word chain is : big-gap-pet-tab
Note

Test your program with the following list

	22
	say how many south marks may be formed dub yam for yas sos biff 
	deaf by da why sam saw sob ross

For additional marks, say how many different four word chains may be formed.

5. Number Triangle

          7
         3 8
        8 1 0
       2 7 4 4
      4 5 2 6 5
The above is a number triangle. Write a program that calculates the highest sum of numbers passed on a route that starts at the top and ends somewhere on the base. You may only move downwards to one of the two numbers diagonally below.

The route in this case is shown in bold: 7, 3, 8, 7 and 5. The sum is 30.

The input will consist of N, the number of rows, followed by N rows of digits that make up the triangle. The output is the highest sum that is reached.

Example

Enter a number triangle :

	5
	7
	3 8
	8 1 0 
	2 7 4 4
	4 5 2 6 5
	The solution is 30.

Test your program with the above triangle and the one below

	4
	1
	1 2
	1 1 3 
	5 3 0 1

Go to the Irish Schools Programming Competition.