Last Updated:
June 25, 1998


Home

Chat Room

C++ Tutorials and Resources

C++ Exercises

Programming Helpers

Links
 

C++ Exercises and Problems




Table of Contents
 
Easiest

Times Table
Perfect Numbers
Even Numbers, Odd Numbers
Guess A Letter Game
Moderate

Pretty Poor Privacy -   (Test Data)
Countdown
Toughest


Instructions On Submitting Your Exercise Problems
Instructions On Submitting Your Answers



1997 - 98 American Computer Science League
Senior Division, Contest #4

"Countdown"

Problem: Given a date in the 1990's, report the number of days from that until January 1, 2000. For example, an input of November 20, 1999 would return a value of 41 bcause 10 days remain in November (21st, 22nd, ..., 30th) and 31 days remain in December.

Input Format: Each date must be entered as a single string, exactly as shown below. There are three formats that you must be prepared to handle:

  • The m/d/yy format is month (1 through 12), day (1 through 31) and the final two digits of year, with slashes as shown. Examples: 9/28/93 and 12/1/98.
  • The d month year format is day (1 through 31) followed by month (January, February, etc.), and year (1990 through 1999). There is a single space between each field. Examples: 28 September 1993 and 1 December 1998.
  • The dd.mm.yy format uses two digits for day, month, and year. Examples: 28.09.93 and 01.12.98.

Sample Input:
  Line #1:   11/20/99
  Line #2:   20.11.99
  Line #3:   20 September 1998
  ...

Sample Output:
  Output #1:   41
  Output #2:   41
  Output #3:   467
  ...

The test data is not available until further notice. Sorry for the inconvenience.

April 22, 1998




"Times Table"

Write a program that generates the times table from 1 to 10. The output should look similar to this:

   1   2   3   4   5   6   7   8   9  10
   2   4   6   8  10  12  14  16  18  20
   3   6   9  12  15  18  21  24  27  30
   .   .   .   .   .   .   .   .   .   .
   .   .   .   .   .   .   .   .   .   .
   .   .   .   .   .   .   .   .   .   .
  10  20  30  40  50  60  70  80  90 100

March 15, 1998




"Perfect Numbers"

The number 6 is said to be a perfect number because it is equal to the sum of all its factors, excluding itself.

6 = 1 + 2 + 3

Write a program that finds and prints the five smallest perfect numbers.

March 15, 1998




"Even Numbers, Odd Numbers"

Using FOR loops, print out all the even numbers from 1 to 20, then print out the odd numbers from 1 to 20. Output the numbers in two columns, one for even numbers, another for odd numbers.

Sample Output:

   2    1
   4    3
   6    5
   .    . 
   .    .
   .    .
  20   19

March 14, 1998




"Guess A Letter Game"

Write a program that generates a random letter, case is not sensitive, so either upper or lower case will be fine. Ask the user to input a character, and output if the input is smaller, larger, or equal to the mystery letter. Remember to convert the input to the case you used. For example, if your random letter is a capital, then you will have to convert all your inputs to capitals. In addition, give a fixed number of chances for your user, and prompt your user how many guesses they have left.

March 14, 1998




1997 - 98 American Computer Science League
Senior Division, Contest #3

"Pretty Poor Privacy"

Problem: A hot topic these days is how to protect the privacy of information on computers. A simple way to protect the contents of a file is to encrypt its contents. For example, if you translated all A's to C's, B's to D's, ..., and Z's to B's, then the string PRIVACY would be encoded as RTKXCEA. This encoded string can be converted back to its original form (only by somebody who knew how the encryption was performed) by converting all C's to A's, and so on. However, in this problem, you don't need to do any decoding.

To make this problem a bit more interesting, you'll be given a number N, between -100 and 100 inclusive, which will indicate how many characters to offset the translation of the first word. For example, N = 2 would convert A's to C's as described above; N = -3 and N = 75 would both convert A's to X's, B's to Y's and so on. For each subsequent word in the string, add to N the number of characters in the previous word. A word is a sequence of characters terminated by a space or the end of the string. We guarantee that there will never be multiple adjacent spaces. For example, if the string were "Now, I think, is the right time.", and N were 5, you'd use N = 9 for converting the second word, N = 10 for the third word, N = 16 for the fourth word, N = 18 for the fifth word, and so on.

And finally, just to make this problem even more interesting, after you've converted the input line, go back and reverse the letters in each word. Don't change the positions of any of the non-letters in the word.

Input: You'll be given 5 input lines, each consisting of a string and an integer N.

Output: Print the encoded version of each string. Maintain the case sensitivity of the input, as shown in the sample below, and leave all non-letters exactly as they appear in the input.

Sample Input:
  Line #1:   PRIVACY, 2
  Line #2:   Easy(?) Question!, 5
  Line #3:   A + 2BC/5A = C, 1
  ...

Sample Output:
  Output #1:   AECXKTR
  Output #2:   dxfJ(?) zaufeqgC!
  Output #3:   B + 2DF/5E = M
  ...

The test data is available below. This is all the information you will need to complete this program. Please don't email me with a bunch of questions, because this is a problem solving question, you should try to solve it yourself. Also, only look at the test data after you have completed your program, because it will ruin the purpose if you know the test data before you complete your program. Email me if you really need help, but try to do it yourself first. Good luck.

March 7, 1998


Test Data - "Pretty Poor Privacy"

The test data is only executed once on your program for your score. If you can it wrong, you can fix your program and try again, but that will not be counted on your score.

Contest One, 5
Contest Three, -75
ThIs -- is a TEST data..., (Really!!!) ?a?b?c?, 6
a ab abc x xy xyz yz, -3
Last one, A + B = 13, 0

Answers:
Contest One, 5
yxjystH qzA

Contest Three, -75
wvhwqrF oobrD

ThIs -- is a TEST data..., (Really!!!) ?a?b?c, 6
yOnZ -- eu o IHTI tmtw..., (zmmbfS!!!) ?o?n?m

a ab abc x xy xyz yz, -3
x zy cba a cb fed ih

Last one, A + B = 13, 0
tsaL irs, I + L = 13

ansicpp@geocities.com 1