The 4th Series Problem Set

1. Brutus and Frutus in a Library II. 2. About the University Librarian 3. Magical Typewriter 4. The Tiling Problem 5. The 276th Customer


1. Brutus and Frutus in a Library II.

Brutus and Frutus really enjoyed their previous visit in a library and so they decided to go there once more. (Isn't it much more pleasant place than dentist's office ?) It was by mere chance that they choose again the book "The CSP Digest" and started to glance through it. When they finally chose the second most interesting problem and wanted to read its solution, they found out that meanwhile all solutions disappeared.

Task: Given is a file containing many numbers of type longint. Write a program which creates the file containing the same numbers sorted from the smallest to the highest. There are so many numbers in the file that they cannot be stored in a memory. However you can assume there is enough space available on your disk.


2. About the University Librarian

"Oook!", said the librarian, when they brought in n more books. In the university library they had n books by various authors on various topics concerning magic. Now the second volume of each book has arrived and they were stored on a bookshelf next to the first volumes of books. Both sets of books, older as well as new, are ordered in the same way. Librarian wanted to have a banana.

Task: In an array A of size 2n (bookshelf) numbers a_1,...,a_n (first volumes of books), b_1,...,b_n (second volumes of books) are stored (in this order). Write a procedure which rearranges the array A so that numbers are stored in order a_1,b_1,a_2,b_2,...,a_n,b_n (the second volume following the first one). Do not use auxiliary array (the librarian has no reserve "auxiliary" bookshelf.


3. Magical Typewriter

Witch Magica has in her office rather mysterious typewriter. She uses it to write her spells on bat leather. I am the crucial part of the typewriter - human arm with a bracelet on which the letters are written. Some of the letters may occur on a bracelet several times. I can rotate about axis leading through my index finger. When Magica presses the red button I print a letter which is just in that moment right above the leather (when I rotate other letters get above the leather). Long writing is very tiring for me and so I decided to write a program which can make my work easier. It should write for given bracelet and text the shortest possible sequence of rotations necessary to print that text. Since I have no head, I would appreciate your help in this matter.

Task: Input for your program consists of two lines - the first one contains the letters on a bracelet (the first letter in a line is just now above the leather). The second line contains the text to be printed. You program should write the shortest possible sequence of instructions LEFT, RIGHT, PRINT and SPACE which can be used to print given text or IMPOSSIBLE if the text cannot be typed using given bracelet.

Example:

Input:


abacd
aba dac

Output:


PRINT RIGHT PRINT LEFT PRINT SPACE LEFT PRINT LEFT
LEFT PRINT RIGHT PRINT

4. The Tiling Problem

Squirrels Anka and Hanka used to live in a very cold dwelling. So they asked their friend elephant for ivory tiles. Tiles are rectangles with size 1sf x 2sf (1sf = one squirrel foot). Squirrels drew a plan of their room and brought it to hippo's office to ask him whether it is possible to tile their room with those tiles. But hippo was just too sleepy to think...

Task: Write a program which for given plan of the room decides whether it is possible to tile this room. The plan consists of spaces and characters # (each such character represents one square of floor with size 1sf x 1sf).

Example:

Input:


 #  #
######
 #  #

Output: NO


5. The 276th Customer

In SoDr software house they celebrate a great anniversary. The 276th customer choose this well-known firm to solve his problem. As usually, the problem was very interesting. The customer was a student of one university and he, as well as many of his colleagues, had no skills in work with fractions. So he needed a library, which would help him to cope with this problem. Customer payed and here is your task.

Task: Write a library which will facilitate the work with fractions. Your library should contain the elementary arithmetic operations as well as procedures for input and output.

Important note: An overflow should not occure in your program provided both operands and the result are in a range you chose.


(C) 1996, Organizers of the CSP