1994  ICPSC 
Senior Division Problems




1. STOP SIGN
Write a program that will generate and print out a  STOP sign as shown below of size N, where N is an integer >= 3. The stop sign should be an octagon with N stars on each side.  The word "S T O P" should be printed in the center of the stop sign. For example, with an input of N=4 the stop sign should appear as follows:


      * * * *
    *         *
  *             *
*                 *
*     S T O P     *
*                 *
*                 *
  *             *
    *         *
      * * * * 


Print a STOP SIGN for each of the following values of N: 3, 4, 5

2. SILLY-SORT
Suppose you translate a whole number  into a string of words, one for each digit, followed by a single space. For example, the number 407 becomes the word string: "FOUR ZERO SEVEN".
Now comes the fun part. You are to write a program that accepts a list of whole numbers, and  prints out the numbers in Silly-Sort order, sorted by their word strings in dictionary order. In particular, given the six numbers 

        7  23  99  54  974  5

your program output for the Silly-Sorted list should be printed in the following order:

        5  54  99  974  7  23  

because "FIVE" < "FIVE FOUR" <.....< "TWO THREE" as strings in dictionary order. 

Test your program with the following two lists of  numbers:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
2 79 662 434 6984 40 160 690 54 55


3. (XY, D)-CIRCULAR NUMBERS
An (XY, D)-CIRCULAR NUMBER is a number whose last two digits are X and Y, where the multiplication of the number by the single digit D is equivalent to moving the last two digits (XY) to the beginning of the number. For example, the number

132832080200501253 is a (53, 4)-circular number because 132832080200501253 * 4 = 531328320802005012.

Write a program that asks for a two-digit number XY and a single digit D, and prints the SMALLEST (XY, D)-CIRCULAR NUMBER or prints a message "NONE" if none exists.

Test your program with (12,4) and (99,9).

4. RATIONAL ORDER
Consider the set of all reduced 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 rational numbers between 0 and 1 with denominators less than or equal to N in order of increasing magnitude. Also, count the total number of  rational numbers found. 

The Programs must reject inputs where N is less than 1 or greater than 100.

Sample Run
Enter the maximum denominator between 1 and 100 : 5
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 rational numbers.

Test your program with N=5, 7.

5. AMAZING WALKS
Given an NxN square divided into N^2 unit cells, it is always possible to walk from the upper left cell, cell 1,  to the lower left cell, cell N^2 - N +1,  by stepping from one cell to a neighboring cell ( one that shares a common side) until you have arrived at your goal having passed through every cell exactly one time.
 For example, here is a sample AMAZING WALK for N=3


----------------
|    |    |    |
| ***********  |
|    |    | *  |
------------*---
|    |    | *  |
|  *****  | *  |
|  * | *  | *  |
---*---*----*---
|  * | *  | *  |
|  * | ******  |
|    |    |    |
----------------

Write a program to count the total number of AMAZING WALKS in a square of size N. 
 
FOR N=3 THE NUMBER OF AMAZING WALKS IS 2.

Test your program with the following values of N: 2,3,4,5,6.

Note: Without some optimization, your program will take too long for N=6.
