Spring 1993 Waterloo Local Contest #2
Testing...Testing...
- Question 1 Ronco's Vegamatic Sentence Generator
- Question 2 Numerical Summation of a Series
- Question 3 Dotty's Folding Dilemma
- Question 4 Star Struck: The Morse Code Generation
- Question 5 A Planimeter Problem
Question 1 Ronco's Vegamatic Sentence Generator
MIA
Question 2 Numerical Summation of a Series
MIA
Question 3 Dotty's Folding Dilemma
Write a program that will keep track of the location of a dot on a piece
of paper as it is being folded.
Input:
The input file will contain 4 different types of records.
- Type 1
- will contain two real numbers separated by one space.
They are, respectively, the width and the height of the paper.
- Type 2
- will contain two real numbers and a character, all separated
by one space. These numbers represent the coordinates of the
dor on the paper. The first number is the distance horizontally
from the upper left hand cornet. The second is the distance fown
from the upper left hand corner. The character will tell you
which side of the paper the dot is on. (T for Top, B for Bottom).
- Type 3
- will contain two unseparated uppercase characters. The first
character will tell you which of the four sides of the paper
you are about to use. (T for Top, B for Bottom, L for Left, R
for Right). The second character will tell you whether to fold
the paper over the top or under the bottom. (O for Over, U
for Under).
- Type 4
- will contain one uppercase `S'. This will tell you to stop
folding the paper.
Output:
The output will consist of which peice of paper you are working on, the
beginning size of the paper, the beginning location of the dot, the size
of the paper and the location of the dot when you have finished folding
the paper.
Process:
This is best explained by example. Place a piece of 8.5 X 11.0 paper on
the desk in front of you. Place a dot on the top surface at 1.00 unit
right of the top left corner and 2.00 units down from the top. Now, take
the top edge of the paper and fold it over the top. The paper is now 8.5
X 5.5 and the dot is on the bottom of page 1. The location of the new
position of the dot is 4.5 units from the top and 1.00 units to the right.
Use these new `coordinates' as the starting positions for the next set of
folding instructions. e.g., TO, would mean you take the top of the paper
and fold it over. Remember that the upper left hand corner is always 0,0.
Sample:
Input: Output:
5.0 8.25 Paper number 1
3.25 8.00 T Beginning paper dimensions: 5.000000 X 8.250000
TO Dot is on TOP of page 1. Position: 3.250000 X 8.000000
LU
S After folding paper. Paper dimensions: 2.500000 X 4.125000
1.0 2.0 Dot is on BOTTOM of page 1. Position: 0.750000 X 3.857000
.55 1.3 B
LO Paper number 2
S Beginning paper dimensions: 1.000000 X 2.000000
Dot is on BOTTOM of page 1. Position: 0.550000 X 1.300000
After folding paper. Paper dimensions: 0.500000 X 2.000000
Dot is on BOTTOM of page 2. Position: 0.050000 X 1.300000
Other Notes:
- The dot will never be on the edge of the paper or a fold line.
- When folding the paper, pretend you are cutting the paper.
In other words, don't be concerned about the thickness of
the fold.
- All input characters will be in uppercase.
Question 4 Star Struck: The Morse Code Generation
The U.S.S. Star Struck, in its continuing mission to seek out new life
forms, to go where no one has wanted to go, has intercepted a series of
transmissions on an ancient and unused radio band. It has been determined
that the messages are in some form of Morse code. Your job is to program
the ship's computer to interpret the header of these messages, and then
code and transmit a message of out own, in prelude to contact.
Input:
The input shall be a table consisting of two columns: A character in the
first column followed by a space followed by its Morse code representation
as a series of `-' and `.' in the second column. This table is terminated
by a `@' in column 1. The code table is followed by an interger on a line
by itself indicating the transmitting speed in words-per-minute (wpm).
This is followed by the message to be transmitted. For the purpose of
transmission, end-of-line characters are not to be sent.
Output:
The output shall be a copy of the message to be sent, one character per
line followed by a listing, as integers of the number of milliseconds
the transmitter will be on and the number of milliseconds the transmitter
will be off to result in the desired speed. Each time is to be preceeded
by at least one character of white space (space or tab) and followed by
one character of white space. Sound times will be followed by a single
character `S' and no sound times will be followed by a single character
`N'. The required inter-character spacing will be the last entry in
a line. Each line will be terminated by a new-line character.
In determining the speed of transmission of messages in Morse code, the
controlling element is the dot `.'. The dash, `-', is three dots in
length. A word is an average five characters plus a trailing inter-word
space. A character is an average tweleve dots (which includes pauses
between sounds), plus a trailing inter-character space. Inter-character
spaces are one dash long, and inter-word spaces are three dashes long.
Sample:
Input: Output:
A .- A 142 S 142 N 426 S 426 N
B -... 1278 N
... b 426 S 142 N 142 S 142 N 142 S 426 N
D -.. a 142 S 142 N 426 S 426 N
... d 426 S 142 N 142 S 142 N 142 S 426 N
O --- 1278 N
... b 426 S 142 N 142 S 142 N 142 S 426 N
Y -.-- o 426 S 142 N 426 S 142 N 426 S 426 N
... y 426 S 142 N 142 S 142 N 426 S 142 N 426 S 426 N
@
5
A bad boy
Question 5 A Planimeter Problem
Given a line segment drawn from 5 to 7 along a reference line marked
in units from an arbitrary origin, it is obvious that the line segment
is 2 units long. In fact, however, we obtain this answer by taking the
imaginary 7 unit long line and subtracting an imaginary 5 unit long line:
7-5 is 2. A planimeter is a mechanical device that employs the
two-dimensional equivalent of this geometric trick to determine the area
enclosed by merely tracing the perimeter.
For example, consider the following walk:
Move Command
Right 3 r 3
Up 1 u 1
Left 1 l 1
Up 2 u 2
Left 3 l 3
Down 2 d 2
Right 1 r 1
Down 1 (closed) d 1
Down 1 d 1
Left 1 l 1
Up 1 u 1
Right 1 (closed) r 1
The enclosed areas are, as one would expect, 9 units and 1 unit.
You are to write a program that accepts a list of motion commands tracing
a series of perimeters, computes and prints the area enclosed by each,
and prints the total area enclosed by all perimeters.
Each motion command is on a line by itself in the form given above: a
single character in the first column indicating the direction (u,d,l,r),
followed by a space and then an integer which indicates a distance to
move in that direction.
There is no command separating the moves tracing one perimeter from those
tracing the next, but each perimeter is a closed walk -- each starting
and ending at the same point. This fact should be used to distinguish
one perimeter from the next. Print each enclosed area as an integer,
right justified in four columns. At end of file, print the total area
accumulated from all walks of perimeters.
For the example given above, your program should output:
9
1
====
10
Notes:
- The maximum displacement from the point of origin may be
large, but will not exceed the range of an integer variable.
- A planimeter can actually measure areas of arbitrary shape
(such as animal skins) and it does this using Greene's Theorem
and some integral calculus, but that's not important for this
question.
Philip Chong
pchong@calum.csclub.uwaterloo.ca
http://csclub.uwaterloo.ca/u/pchong