Sewickley Academy Programming Team
Programming Contest:  31-Jan-2002
David Kosbie (Faculty Advisor)
Sewickley Academy

Link to Programming Contests home page.

Team Questions (SRU-style)

The following programs will be tested with redirection, as in q1.exe < testFile1.txt.

Question 1.  Read in four whole numbers from the first line of the input file.  Print the difference between the largest and the smallest numbers.

Question 2.  Read in three whole numbers:  d, n1, and n2, such that 0 <= d <= 9.  Print out all the prime numbers between n1 and n2 inclusively, which contain the digit d.

Question 3.  Read in integers a, b, and c.  These describe the parabola y = ax2 + bx + c.  Next, read in integers d and e.  Finally, print out every point (one per line) x,y which is on that parabola, and in which y is in the interval [d,e], and which both x and y are integers.  After that, print one last line with the number of such points printed out.

Question 4.  Here you will write a simple loan calculator.  Read in a single line containing three whole numbers: loanAmount, interestRate, and minPayment where loanAmount is the initial loan amount in dollars, interestRate is the annual interest rate as a percentage (so 7 indicates 7%), and minPayment is the minimum amount in dollars for each monthly payment.  While not typical, here we assume that the monthly interest rate is simply 1/12th of the annual interest rate, and that the interest for each month is simply the oustanding principal multiplied by the monthly interest rate and rounded to the nearest penny.  We also assume that each month the minimum payment is made, except the final month when the remaining interest and balance is paid off.  Your program should output a single line with the following information, where dollar amounts are to the nearest penny:  number of months until loan is paid off, total interest paid, total principal paid, total payment.

Question 5.  In this question, you will write a substitution cypher.  To do this, you will create a hash table with 26 buckets.  Each bucket can hold no more than one entry, and collisions are handled by finding the next empty bucket in the hash table, wrapping around to index 0 if necessary.  You will read in two whole numbers, m1 and m2, and the hash function is hash(char) = (m1 * char + m2) % 26, where char is 0 for 'A' or 'a', 1 for 'B' or 'b', and so on.  Hash each letter from A to Z in order.  Thus, each <letter> is in some bucket b.  The substituion for <letter> is the bth letter, where 'A' is the 0th letter.  So, if letter 'W' winds up, say, in bucket 3, then the substitution for 'W' is 'D'.  After reading in m1 and m2 (alone on the first line), you will read in a series of lines each containing a string with no spaces in it.  For each line, print out the corresponding line with substituted characters.  Note that Uppercase letters are substituted in Uppercase, lowercase are substituted in lowercase, and nonletters are not modified but copied directly.  Halt on an empty line.

Question 6.  Write a program to find a path in a 3-dimensional world from (0,0,0) to (1,1,1).  You may only move one space at a time, and then only parallel to an axis, and so the 6 legal moves are denoted:  x++, x--, y++, y--, z++, z--.  The problem is that there are blocks in your way -- these are listed as three integers on a line, these being the point (x,y,z), with the last line containing the point (0,0,0) which is just a sentinel (it is not part of the data).  As you may have guessed, you may not move into a block.  Your task is to read in all the blocks, then print out the sequence of moves (comma-separated) which produces the shortest path from (0,0,0) to (1,1,1).  You are guaranteed you can make it in 9 or fewer steps.