Slippery Rock University

Computer Science Department

Official Problem Set

Intramural Computer Programming Contest

Fall, 2002


1. Integral Right Triangles


A long time ago, the Egyptians figured out that a triangle with sides of length 3, 4, and 5 had a right angle as its largest angle. You must determine if other triangles have a similar property.


The Input:

Several lines of input, each with three positive integers, less than 10,000, in ascending order, denoting the lengths of the sides of a triangle.


The Output:

For each input line, a line containing "right" if the triangle is a right triangle, and a line containing "wrong" if the triangle is not a right triangle.


Sample Input:

6 8 10

25 52 60

5 12 13


Output for Sample Input:

right

wrong

right



2. Factorials


The factorial of an integer n, written n!, is the product of all the integers from 1 through n inclusive. The factorial quickly becomes very large: 13! is too large to store in a 32-bit integer on most computers, and 70! is too large for most floating-point variables. Your task is to find the rightmost non-zero digit of n!. For example, 5! = 1 * 2 * 3 * 4 * 5 = 120, so the rightmost non-zero digit of 5! is 2. Also, 7! = 1 * 2 * 3 * 4 * 5 * 6 * 7 = 5040, so the rightmost non-zero digit of 7! is 4.


The Input:

Several lines of data, each with one integer n, between 1 and 1000 inclusive. The last line will contain a negative integer flagging the end of data.


The Output:

The value of n, whitespace, and the rightmost non-zero digit of n!, for as many values of n as are given in the data file. One line of output per value of n.


Sample input:

5

789

1000

-1


Output for Sample Input:

5 2

789 4

1000 2



3. Euclid's Game


Two players, Stan and Ollie, play, starting with two natural numbers. Stan, the first player, takes the smaller of the two numbers, and finds the largest positive multiple of this number that is still less than or equal to the larger number. He subtracts this multiple from the larger number. The difference replaces the larger number. Then Ollie, the second player, does the same with the two resulting numbers, then Stan, etc., alternately, until one player is able to subtract a multiple of the lesser number from the greater to reach 0, and thereby wins. For example, the players may start with (25,7):


25 7 (Stan's turn. 25 – 3 * 7 = 4. 4 replaces 25.)

4 7 (Ollie's turn. 7 – 1 * 4 = 3. 3 replaces 7.)

4 3 (Stan's turn. 4 – 1 * 3 = 1. 1 replaces 4.)

1 3 (Ollie's turn. 3 – 3 * 1 = 0. 0 replaces 3,)

1 0 (and Ollie wins.)

and Ollie wins.


The Input:

A number of lines, each line containing two positive integers which are the starting two numbers of the game. Stan always starts.


The Output:

Print the play and results of the game in the same format as the example above. Skip a line and repeat until there is no more data.


Sample Input:

12 9

13 756


Output for Sample Input:

12 9

3 9

3 0

and Ollie wins.


13 756

13 2

1 2

1 0

and Stan wins.



4. Ordered Fractions


Consider the set of all reduced fractions (rational numbers) between 0 and 1 inclusive with denominators less than or equal to n.


Here is the set when n=5:


0/1 1/5 1/4 1/3 2/5 1/2 3/5 2/3 3/4 4/5 1/1


Write a program that, given an integer n between 1 and 100 inclusive, prints the fractions in order of increasing magnitude. You should also print the total number of fractions. Don't forget that, for some larger values of n, the output will take several lines to print. If this is the case, break lines after every 13th fraction.


The Input:

A series of lines, each with one integer between 1 and 100, inclusive.


The Output:

The space-separated fractions with a newline after every 13th fraction and the last fraction, and a statement of the number of fractions.


Sample Input:

5

3


Output for Sample Input:

0/1 1/5 1/4 1/3 2/5 1/2 3/5 2/3 3/4 4/5 1/1

There were 11 fractions.

0/1 1/3 1/2 2/3 1/1

There were 5 fractions.



5. Full Alphabet


It is said that teletype operators, after establishing a connection, would type the line:

THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG

This line is apropos because it contains every letter of the alphabet. You are to test other lines to see if they have the same property.


The Input :

The input to your program consists of several lines, each containing uppercase letters of the alphabet and spaces. No line contains more than 80 characters.


The Output

For every line of input, print

Sufficient.

if it contains every letter of the alphabet, or

Deficient.

if it does not.


Sample Input:

NOW IS THE TIME FOR ALL GOOD MEN TO COME TO THE AID OF THE PARTY

THE FOX BROWN JUMPS QUICK DOG LAZY OVER


Output for Sample Input:

Deficient.

Sufficient.




6. Zero Sum


Consider the sequence of digits from 1 through n (where n ≤ 9) in increasing order, 1 2 3 4 5 . . . n , and insert either a (+) for addition or a (-) for subtraction, or no character to run the digits together. Now sum the result and see if you get zero.


Write a program that will find all sequences of length n that produce a Zero Sum. Your program should stop when a negative number is given for n.


The Input:

A series of integers between 1 an 9 inclusive, one per line, followed by a line containing a negative integer.


The output:

All of the above-described arithmetic problems, an equal sign, and the answer, one per line. Skip a line in the output after processing each line of input. A non-algorithmic solution will be considered incorrect.


Sample Input:

7

8

-9


Output for Sample Input:
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
1 - 23 + 4 + 5 + 6 + 7 = 0
1 - 23 - 45 + 67 = 0


1 + 2 + 3 + 4 - 5 - 6 - 7 + 8 = 0
1 + 2 + 3 - 4 + 5 - 6 + 7 - 8 = 0
1 + 2 - 3 + 4 + 5 + 6 - 7 - 8 = 0
1 + 2 - 3 - 4 - 5 - 6 + 7 + 8 = 0
1 + 23 - 45 + 6 + 7 + 8 = 0
1 - 2 + 3 - 4 - 5 + 6 - 7 + 8 = 0
1 - 2 - 3 + 4 + 5 - 6 - 7 + 8 = 0
1 - 2 - 3 + 4 - 5 + 6 + 7 - 8 = 0
1 - 23 - 4 + 5 + 6 + 7 + 8 = 0
12 - 34 -56 + 78 = 0