Westminster College 2007 High School Programming Contest October 9, 2007

advertisement
Westminster College
2007 High School Programming Contest
October 9, 2007
Rules:
1. There are six questions to be completed in two and 1/2 hours.
2. All questions require you to read the test data from standard input and write results to standard
output. You should not use files for input or output.
3. The allowed programming languages are C++ and Java.
4. All programs will be re-compiled prior to testing with the judges’ data.
5. Programming style is not considered in this contest. You are free to code in whatever style you
prefer. Documentation is not required.
6. Judges’ decisions are final. No cheating will be tolerated.
2006 Westminster High School Programming Contest
Problem A:
1
All Keyed Up
Text-messaging done on cellphones can be done using a keypad similar to the one shown below.
abc
def
ghi
jkl
mno
5
6
pqrs
tuv
wxyz
7
8
9
1
4
2
3
To type an ‘a’, you press button 2 one time; to type a ‘b’, you press button 2 twice, and so on. Thus,
to type the word “java” requires 6 button presses (buttons 5,2,8,8,8 and 2). To type a word like “cab”
is a little trickier, since you must pause between keystrokes whenever consecutive letters appear on the
same number. Typing “cab” would go as follows: 2, 2, 2, pause, 2, pause, 2, 2. For this problem, you
will be given a word and must determine how long it takes to type it in, assuming that you can press
keys at a speed of 4 per second, and that each pause is a second long.
Input
There will be multiple input sets. Each input set will consist of a single line, containing a single word.
The last word of the file will be “stop”.
Output
For each input set, output the word, followed by a colon and a space, and then followed by the time
(in seconds) it takes to type it in. Upper case letters should be treated the same as lower case letters
on the keypad, but you should echo the input exactly as it is printed in the input file (see the example
below).
Sample Input
java
cab
Cellphone
stop
Sample Output
java: 1.5
cab: 3.5
Cellphone: 7.25
stop: 2.25
2006 Westminster High School Programming Contest
Problem B:
2
You’ve Got Mail
Many Internet companies perform a lot of scanning of e-mails and other Internet traffic looking for
various types of information. For this problem you will take part in this border-line nefarious activity
by searching for e-mail addresses embedded in text. An e-mail address is defined as follows: any
consecutive sequence of non-blank characters, with a single ‘@’ located somewhere inside, but not on
either end. Thus the following are valid e-mail address:
bonomojp@westminster.edu
longish type user name@strange.../sdf?242jk.name
a@b
The following would not be considered e-mail address
bonomojp@
a@b@c
Input
There will be a single input test case. It will start with an integer n indicating the number of lines of
text to follow. After this will be the n lines of text.
Output
If one or more e-mail addresses are found on a line, output the line number and each e-mail address,
separated by a single space (use the format shown in the example).
Sample Input
5
To find out more about majoring in CS @ Westminster
College, contact bonomojp@westminster.edu, lenoxtl@westminster.edu or
shaffecd@westminster.edu (brought
to you by the folks
at shameless_plug@for-our-department).
Sample Output
Line 2: bonomojp@westminster.edu, lenoxtl@westminster.edu
Line 3: shaffecd@westminster.edu
Line 5: shameless_plug@for-our-department).
2006 Westminster High School Programming Contest
Problem C:
3
For All the Marbles
Amanda Gate is putting her world-renown collection of antique marbles up for auction, but she’s running
the auction slightly differently than normal. Everyone has to submit his/her bid in writing, and then
Amanda will award her collection to the highest unique bid, i.e., the highest bid which only one person
made. So for example, if there were bids of $100, $150, $90, $140 and $150, the person who bid $140
would get the collection. If that first bid of $100 was changed to $140, then the person bidding $90
would get the collection. If there is no unique bid, Amanda will just keep her collection, and try to
auction it off some other time.
Input
The input file will consist of multiple test cases. Each input case will consist of two lines. On the first
will be a positive integer n indicating the number of bids. The maximum value of n will be 1000 (lots
of marble enthusiasts out there). The second line will contain the n bids, each a positive integer (there
will be no $ signs in the input). A value of n = 0 indicates end-of-input.
Output
For each input test case output either the highest unique bid (with a $ sign in front of it) or the phrase
No unique highest bidder.
Sample Input
5
100 150 90 140 150
3
85 85 85
0
Sample Output
$140
No unique highest bidder
2006 Westminster High School Programming Contest
Problem D:
4
Non Stop Op
Opish is a nonsense language which converts normal English words to Opish words using the following
simple rule: after each consonant, add the letters “op”. Thus the word “hello” is changed to “hopeloplopo”, and “strengths” becomes “soptopropenopgoptophopsop”. For the purpose of this problem the
letter ‘y’ will be considered a consonant unless it’s at the end of a word.
Input
The input file will consist of multiple test cases. The first line of the file will be an an integer n indicating
the number of input cases. After this will be n lines, each line containing one or more words.
Output
For each input line output the Opish version of the line.
Sample Input
3
hello
"To be, or not to be..."
Is this the end?
Sample Output
hopeloplopo
"Topo bope, orop nopotop topo bope..."
Isop tophopisop tophope enopdop?
2006 Westminster High School Programming Contest
Problem E:
5
And the Survey Says...
Mr. Gene Green has a small problem. He owns a plot of land, and the local government has decided to
put a road through it. That’s not his problem though, since the government intends to compensate him
handsomly: they’ll pay $100 for each foot long length of the road through his property. The government
has sent out a surveyor to measure the length and herein lies Gene’s problem, since he doesn’t trust
this surveyor at all. He would like you to write a program to determine this length for him. He might
even componsate you $10 per line of code (actually, that’s still under negotiation).
For the purposes of this problem, the plot of land will be a rectangle, with sides parallel to the x and
y axes. The road will be a straight line segment which will start and end outside of the rectangle and
pass through the two sides parallel to the y axis, as in the figure below.
r(300, 400)
(340,
260)
r
r
(40, 60)
r
(100, 0)
Input
The input file will consist of multiple test cases. Each test case will consist of a single line containing
eight integers. The first two values will be the coordinates of the lower left-hand corner of the rectangle;
the next two values with be the coordinates of the upper right-hand corner; the next two values will be
the coordinates of one of the two endpoints of the line; and the final two values will be the coordinates
of the other endpoint. All values will lie between 0 and 1000 and be in units of feet. A line containing
eight 0’s will terminate input
Output
For each test case, output the length of the road lying inside of the plot of land, rounded to the nearest
integer.
Sample Input
100 0 300 400 40 60 340 260
500 500 600 600 450 550 650 550
0 0 0 0 0 0 0 0
Sample Output
240
100
2006 Westminster High School Programming Contest
Problem F:
6
Calling All Programmers
A local radio station is holding a phone-in contest, and deejay J-Z Phus is in charge of administering
the contest. He goes on the air at random times and announces things like “The fifth caller will get a
chance for the grand prize”. At this point, the switchboard lights up with dozens of callers. All these
callers show up on a monitor in front of J-Z numbered 1, 2, 3, etc. J-Z could just pick caller number
5 at this point, but since he figures that everyone basically called in at the same time, he has decided
on a different method. He picks a random number – say 7 – and then starts eliminating every seventh
caller. If he hits the end of the switchboard while counting, he cycles back to the beginning, but once a
caller is eliminated, their position is no longer used in the count. After eliminating 4 callers, he moves
down 7 more positions and obtains his “fifth” caller. The figure below show how this would work if
J-Z’s switchboard held 10 callers. In this case, the caller in position 3 is selected as the “fifth” caller.
1 2 3 4 5 6 7 8 9 10 ← Caller’s Switchboard Position:
p p p p p p p p p p p p @p p p p p p p p
@ 1ST COUNT: 1
2
3
4
2N D COUNT: 4
5
6
7
3RD COUNT: 6
7
5
6
7
Position 7 eliminated
p p p p p p @p p p p p p @p p p p p p p p
@ @ 1
2
3
Position 4 eliminated
p p @p p p p @p p p p p p @p p p p p p p p
@
@
@
1
2
3
4
5
Position 2 eliminated
1
2
3
4
5
6
Position 1 eliminated
1,7
2
3
4
5
6
Position 3 selected as “fifth” caller
p p @p p p p p p @p p p p p p p p
@p p @p p @ @ @ @ 4T H COUNT: 7
a a @p p p p p p @p p p p p p p p
@p p @p p @ @ @ @ 5T H COUNT:
Of course, the choice of “fifth” caller, the number of callers, and the use of the number 7 can change
from call-in to call-in. You are to write a general program to determine which caller is selected given
all of the pertinent information
Input
The input file will consist of multiple test cases. Each test case will consist of a single line containing
3 positive integers n m k, where n is the number of callers on the switchboard, and m is the number
of positions J-Z skips over each time until he gets to the k th caller. The value of n will always be ≥ k.
In the above example, n = 10, m = 7 and k = 5. The maximum value for any of there values is 100. A
line containing three zero’s will terminate input.
Output
For each test case, output the position of the caller chosen as the k th caller.
Sample Input
10 7 5
20 1 20
0 0 0
Sample Output
3
20
Download