Showing posts with label basic. Show all posts
Showing posts with label basic. Show all posts

Sunday, March 14, 2010

The Fourth Annual Computer Competition (Part 4 of 4)

(Introduction and Part 1, Part 2, Part 3, Part 4)

The fourth question, Question #5.

Question #5: Senior Division

Compact Disks (CD's) offer the latest advantages in digital sound. Each disk is capable of prividing almost 75 minutes of music. You are currently creating a catalog of your disks (on your computer, naturally) that will list the total time (in hours:minutes:seconds) fro each CD. Unfortunately, while most disk labels list the time for each selection, many do not list the total time for the complete album (although must CD players display this information when you first insert the disk prior to playing it.)

Write a program that (a) asks for the number of selections on the disk (b) asks for the time of each selection in the exact format [minutes:seconds] -- including the colon and (c) outputs the total time of the CD in the format [HH:MM:SS] (Hours:Minutes:Seconds). NOTE: 00:63:29 would be wrong. 01:03:29 would be correct,etc,

IMPORTANT INFORMATION: You may assume that no selection is over 59 minutes and 59 seconds long [59:59] and that the judge will input the data with no spaces between the numbers and the colon. However, the judge may or may not input the minute information with a leading zero. For example, your program should be able to handle 2 minutes and 12 seconds input by the judge either in the form 2:12 or 02:12. Finally your output must be in the format HH:MM:SS or it will not be judged correct. That is, there must be two digits for each position (hours, minutes and seconds) and the output must not have any spaces between the digits and the colons. Some example include (see the SAMPLE RUNS for others):

Correct:Incorrect:Correct:Incorrect:
00:07:3300:7:3302:13:1202 : 13 : 12

SAMPLE RUNS
RUN

HOW MANY SELECTIONS ON THE DISK? 5

TIME FOR SELECTION # 1 (MINUTES:SECONDS)? 29:45
TIME FOR SELECTION # 2 (MINUTES:SECONDS)? 13:32
TIME FOR SELECTION # 3 (MINUTES:SECONDS)? 9:12
TIME FOR SELECTION # 4 (MINUTES:SECONDS)? 02:12
TIME FOR SELECTION # 5 (MINUTES:SECONDS)? 12:52

TOTAL TIME OF DISK = 01:07:33

RUN

HOW MANY SELECTIONS ON THE DISK? 3

TIME FOR SELECTION # 1 (MINUTES:SECONDS)? 4:59
TIME FOR SELECTION # 2 (MINUTES:SECONDS)? 26:26
TIME FOR SELECTION # 3 (MINUTES:SECONDS)? 01:09

TOTAL TIME OF DISK = 00:32:34




The Fourth Annual Computer Competition (Part 3 of 4)

(Introduction and Part 1, Part 2, Part 3, Part 4)
The third question, Question #4.

Question #4: Senior Division

The integers 12, 21, 13 and 31 have the following characteristic:
12 times 12 = 144 and 21 times 21 = 441
13 times 13 = 169 and 31 times 31 = 961
Write a program that identifies all 3-digit integers (if any) between 100 and 400 for which this same kind of relationship holds. (That is, a 3-digit number whose square and the square of its "reverse" are mirror images.)

Important notes:

The number and its "reverse" must:
(a) both be true 3-digit numbers
(b) not be identical.
Examples: the following integers (among others) do not qualify:
100 (because its reverse integer is 1)
120 (because its reverse integer is 21)
121 (because its reverse integer is identical)

SAMPLE RUN
NOTE:

When your program is RUN by the judge it should list all the integers between 100 and 400 that qualify or state that no integers qualify, if that is the case.

The Fourth Annual Computer Competition (Part 2 of 4)

(Introduction and Part 1, Part 2, Part 3, Part 4)

Question #3: Senior Division

Write a program that accepts a sentence for input and outputs the sentence with the letters in each word arranged in alphabetical order, and the words in order of length. Words must still be separated by spaces. If two rearranged words are of equal length they are to be placed in alphabetical order of the output "sentence".

NOTE: The judge will input only upper-case letters and will terminate the sentence with a period. This will be the only punctuation in the sentence and must remain at the end of the output sentence.

SAMPLE RUNS

RUN
WHAT IS YOUR SENTENCE? THIS IS A SENTENCE FOR YOU TO EXAMINE.
A IS OT FOR OUY HIST AEEIMNX CEEENNST.

RUN

WHAT IS YOUR SENTENCE? WE ARE NOT ALL HERE NOW.
EW AER ALL NOT NOW EEHR.


The Fourth Annual Computer Competition (Part 1 of 4)

(Introduction and Part 1, Part 2, Part 3, Part 4)

Introduction

During my junior and senior years at high school I participated in a county-wide computer programming competition.

The day before the first competition, my junior year, the president of the computer club challenged me to a quick on-paper coding competition to see who should go. I beat him handily, and he was kind enough to give me the spot. Charles was a brilliant guy who I'm sure did just fine without the competition on his resume.

Both years, the competition went like so: every student was allocated an observer-judge. The judge was responsible for resetting the programming environment, clearing code and data, watching the student during the test, and then, when the student was done, would test the program with a predetermined data set. Correct exact results meant the student earned one point. Any incorrect result meant zero points.

The junior year I tied for third place with four other kids, resulting in a sudden-death run-off. (I remember getting at least one question incorrect. Did I get two wrong? My ego is struggling with the possibility.) I'm positive that had I not paused to test my program during the run-off I would have taken third-place, and the TRS-80 would have been mine. Alas.

The senior year's competition was the day after my prom, and I chose not to attend the prom in order to get a good night's rest. (This is a lie; I didn't attend the prom for plenty of reasons, most of which was I didn't fit in. My girlfriend and I had dinner at Gasho of Japan instead.) I don't remember doing well enough to win or place.

Tonight, while going through some old boxes in the basement, I came across one of the competition packets. There's no year on the packet, so I can't tell for which competition it was. There are four questions, labeled two through five, meaning that one of the questions is missing.

I'll publish the four questions, each as its own blog post. I won't include sample answers, because mine were built and destroyed quicker than sand sculptures. Plus they were written in BASIC, and I love you, but not that much.

The first question, Question #2.

Question #2 Senior Division

Write a program that will ask for six 3-digit numbers (without signs) to be input one at a time. ANY 3-digit number is valid. (Examples: 123, 049, 899, etc...). If anything else is input (letters, etc.) the program MUST output the EXACT error message "PLEASE INPUT THREE DIGITS ONLY", and then request the number again. After SIX 3-digit numbers are properly input the program is to tally the digits according to their position and output a table listing how many times a particular number appears at each position (hundreds, tens and units place.) See the SAMPLE RUN for clarification.

NOTES:
1. Try to make your output table easy to read, but do not worry about all numbers lining up perfectly since various computers differ slightly in formatting. [The judge will be looking for accuracy of output, not formatting of output.]
2. To make your task a bit easier you may assume that the judges will NOT attempt to input any commas or quotation marks. Any other input, however (letters, numbers, +/-, etc.) is "fair game", so make sure to test your program thoroughly.

SAMPLE RUN
RUN
3-DIGIT NUMBER 1? 364
3-DIGIT NUMBER 2? XYZ
PLEASE INPUT THREE DIGITS ONLY
3-DIGIT NUMBER 2? 446
3-DIGIT NUMBER 3? 780
3-DIGIT NUMBER 4? 8994
PLEASE INPUT THREE DIGITS ONLY
3-DIGIT NUMBER 4? 507
3-DIGIT NUMBER 5? 5B7
PLEASE INPUT THREE DIGITS ONLY
3-DIGIT NUMBER 5? 060
3-DIGIT NUMBER 6? 492


TALLY   HUND    TEN     UNIT
-----   ----    ---     ----
ZERO     1       1       2
ONE      0       0       0
TWO      0       0       1
THREE    1       0       0
FOUR     2       1       1
FIVE     1       0       0
SIX      0       2       1
SEVEN    1       0       1
EIGHT    0       1       0
NINE     0       1       0