Slippery Rock University
Computer Science Department
High School
Computer Programming Competition
February 5, 2002
Official Problem Set
1) Given the lengths of three line segments, determine whether the segments could be assembled into a triangle. Input is three numbers on one line; output is the word yes or no.
Example: If the input is
3.0 4.0 5.0
The output should be
yes
Your test data files for this problem are
For C, C++, and Pascal: data1a.ssv and data1b.ssv
For BASIC: data1a.csv and data1b.csv
2) You are given a series of lines of names in standard last-name-first order: last name first, comma and space, optional middle-initial-with-period or middle name and space, and first name or first-initial-and-period last. There is one full name per line. For each line of input, fix capitalization so the first letter or initial of each name is capitalized and the rest of the name is in lower case, and rewrite the line in first-middle-last order, single-space separated.
There will be no names that are tricky to capitalize, such as McDougal or deForest. No line will be longer than 40 characters.
Example: If the input is
Smith, G. Warren
Bluster, PhinEAS T.
SQUEEB, CALDEHAM Y.
truman, harry
The output should be
G. Warren Smith
Phineas T. Bluster
Caldeham Y. Squeeb
Harry Truman
Your test data file for this problem is data2.dat
3) You are given a file of 20 lines to read into an array. Each row of the array contains three numbers: a number with which to do arithmetic, a code number for an operation on the first number (1 =>+, 2=>-, 3=>*, and 4=>/), and the number of the next row in the array to be processed. We are counting from zero, i.e., the first row is row zero. A variable called the accumulator stores the result of the most recent computation. At each row, operate on the value in the accumulator and the data in the line. For example, if the accumulator contains 10, and the current row contains 3 2 11, since 2 is the code for subtraction, perform 10 - 3 = 7, store 7 as the new value in the accumulator, and go to row 11 for the next step.
Use zero as your initial accumulator. Execute row zero first. Continue until the next line to be processed is out of range (less than zero or greater than 19). Print your final accumulator value and stop. Do not assume that the accumulator will always store an integer. You are not responsible for avoiding division by zero.
Example: If the input file starts like
25 1 2
10 3 -1
5 4 1
:
We set the accumulator to zero. The first row (row zero) says add 25 (giving 25) and go to row 2. Row 2 (the third row) says divide by 5 (giving 5) and go to row 1. Row 1 says multiply by 10 (giving 50), and -1 is out of range, so print 50 and stop.
Output:
50.0
Your test data file for this problem is
For C, C++, and Pascal: data3.ssv
For BASIC: data3.csv
4) A convex polygon lies in the x-y plane such that the two vertices that are farthest apart lie on the x-axis. Given the coordinates of its vertices, find the area of the polygon. (A convex polygon is one whose vertices all point outward.)
Each line in the data file contains a pair of real numbers. Each pair is the coordinates of a vertex of a polygon. The first ordered pair will always be the coordinates of a point on the x-axis, and the last point will be the same point as the first one. (When you read a second point whose y-value is 0.0, you know you have read all the points above the x-axis. When you find a point whose coordinates are the same as the first point, you know you have read all the coordinates of the polygon.) Hint: depending on how you attack the problem, areas in the second and fourth quadrants may come out negative; if so, you need to compensate so that all areas are positive quantities.
Example: If the input is
-10.0 0.0
-5.0 6.0
2.0 6.0
8.0 0.0
0.0 -4.0
-10.0 0.0
We have an 5-sided polygon (pentagon). The correct output is
111.0
Your test data file for this problem is
For C, C++, and Pascal: data4.ssv
For BASIC: data4.csv
5) Given nine 7-letter words, print any sets that are anagrams of each other. Print one set of anagrams to a line. If there are no anagrams in the data, print "None found." (without quotes.)
Example: given the data
soldier
decimal
caliper
irately
version
medical
replica
married
claimed
Your output might be
caliper replica
claimed decimal medical
Your test data file for this problem is data5.dat
6) In a Caesar Cipher, plaintext (ordinary, unencrypted text) is modified by substituting for each letter in the plaintext the letter n letters ahead of it in the alphabet, wrapping around. Thus, if n=3, we substitute d for a, e for b, ..., z for w, a for x, b for y, and c for z.
You are given a cyphertext (encrypted text) believed to have been enciphered using a Caesar Cipher. You know some words, given on the first line of the data file, that might appear in the plaintext, and you will try to decode the message by looking for one of the known words in the first line of cyphertext (line 2). For example, if the message was from the navy, we would expect to find words like vessel, ocean, sea, or admiral in the plaintext, so these words would preceed the first line of cyphertext in the data.
Try all values of n from 1 to 26, decrypting the cyphertext and looking for any of the words given in the first line of the data file. If any one is found, print the decoded cyphertext line by line and quit. If no value of n results in any of the words from the first line appearing in the decrypted text, print the message Plaintext not found. (including the period) and quit.
The message and words to scan for will be in all capital letters, but may include punctuation. When decoding, modify only the letters, not the punctuation. Words will be separated on a line by one blank (space), and possibly a punctuation mark. No line will be blank or longer than 80 characters, and the file will be no longer than 5 lines. Do not match substrings. For example, the word "I" will match only the word "I", not a word that contains an "I". Note that the word "SEA" would match "SEA;" but not "SEAS" and not "SEAMAN".
BASIC programmers: your data files will end with the line, "EOM" (meaning "end of message"), which may be a 6th line.
Example 1: if the input is:
VESSEL OCEAN SEA ADMIRAL
GJXVODJI VOGVIODX JXZVI IZVM VUJMZN. VYHDMVG EJIZN CVN
CDBC AZQZM. MZLPZNO KZMHDNNDJI OJ OMVINKJMO CZM OJ
CJNKDOVG DI VUJMZN.
The output should be:
LOCATION ATLANTIC OCEAN NEAR AZORES. ADMIRAL JONES HAS
HIGH FEVER. REQUEST PERMISSION TO TRANSPORT HER TO
HOSPITAL IN AZORES.
Example 2: if the input is:
ELVES DWARF HOBBIT THE
YXO BSXQ DY BEVO DROW KVV, YXO BSXQ DY PSXN DROW,
YXO BSXQ DY LBSXQ DROW KVV, KXN SX DRO NKBUXOCC LSXN DROW.
The output should be:
Plaintext not found.
Your test data files for this problem are
For C, C++, and Pascal: data6a.dat and data6b.dat
For BASIC: data6a_basic.dat and data6b_basic.dat