Previous Competition Sample Problems

Contract All | Expand All

Samples from the 2013 Programming Contest

Expand all samples | Contract all samples

Matching Special Characters

Problem Description

In this problem you must scan a line of characters and determine if each of three special characters occur in pairs. The special characters are parenthesis, brackets, and braces. These are ( ), [ ], and { }. The order is not important. Any other characters should be ignored.

Detailed Requirements

  • Read a line of characters. This line will not exceed 80 characters. You must allow the user to enter all the characters at one time. You cannot require the user to hit enter after each character.
  • Determine if there is one left parenthesis for each right parenthesis.
  • Determine if there is one left bracket for each right bracket.
  • Determine if there is one left brace for each right brace.
  • Ignore any other character.
  • Display "All special characters have a match" if each special character has a match. Display "Not all special characters have a match" if any special character does not have a match.
  • Add comments at the top of your source code for your name and the problem number.
  • The judges will enter additional test data not provided below to further test your application. You don't need to validate the input. The judges will only enter valid data.

Output

Display a single line indicating whether all special characters have a match for each test case. Format the output exactly as shown in the test data below.

Test Data

InputOutput
{)(} All special characters have a match.
}){( All special characters have a match.
{ae{)} Not all special characters have a match.
({{{asas[sad])}}dsas} All special characters have a match.
{tt}tt((t Not all special characters have a match.

A sample console interface is provided below. Your user interface is not being judged. Each set of data can be tested by rerunning the application.

Enter characters:
{)(}
All special characters have a match.

Figure 1

A sample graphical user interface is provided below. Your user interface is not being judged. Each set of data can be tested by rerunning the application.

Figure 2

Moving Averages

Problem Description

A moving average is often used to “smooth” a series of numbers to see if a trend exists. For example you could plot a series of stock prices taken daily for a year and see if there is a trend. Alternatively you could plot the moving average of those same stock prices. The moving averages should give a truer representation of the actual trend.

Create an application that will display the moving averages of a series of numbers. There will be n numbers in this series. The subset of numbers to average will be fixed at some value called s. When n = 10 and s = 4 we would want to calculate a moving average of 10 numbers 4 at a time.

Assume the numbers are 1, 2, 3, 4, 5, 6, 7, 8, 9, and 10.
The moving averages would be 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, and 8.5.
These are calculated by averaging (1 + 2 + 3 + 4), then averaging (2 + 3 + 4 + 5), then averaging (3 + 4 + 5 + 6) and so on.

Detailed Requirements

  1. Read a value for the number of items in the series. This will be a positive integer greater than 1 and less than 101.
  2. Read a value for the subset size. This will be a positive integer. It will be less than the number of items in the series.
  3. Read each number in the series. The numbers can be any floating point value – positive, negative, or zero. You must allow all the numbers to be entered at once. In other words, you cannot require the user to press enter after each number is entered. Separate each number by a space.
  4. Calculate and display the moving averages. Separate each number by a space.
  5. Add comments at the top of your source code for your name and the problem number.
  6. The judges will enter additional test data not provided below to further test your application. You don't need to validate the input. The judges will only enter valid data.

Output

Display a single line containing the moving averages as shown in the Output column of the Test Data section below.

Test Data

Numbers in SeriesSize of SubsetNumbers in SeriesOutput1
10 3 .5 1.5 2.5 3.5 4.5 5.5 6.5 7.5 8.5 9.5 1.5 2.5 3.5 4.5 5.5 6.5 7.5 8.5
3 2 10 20 30 15.0 25.0
8 4 1 2 3 4 5 6 7 8 2.5 3.5 4.5 5.5 6.5
11 6 10 20 30 40 50 60 10 20 30 40 50 35.0 35.0 35.0 35.0 35.0 35.0

1Your output may have additional decimal positions. Correct output will be judged only to the decimal precision shown in the sample output. Additional numbers of decimal output after that will not be considered incorrect.

A sample console interface is provided below. Your user interface is not being judged. Each set of data can be tested by rerunning the application.

Enter number in series:
10
Enter subset size:
3
Enter numbers:
.5 1.5 2.5 3.5 4.5 5.5 6.5 7.5 8.5 9.5

1.52.53.54.55.56.57.58.5

Figure 1

A sample graphical user interface is provided below. Your user interface is not being judged. Each set of data can be tested by rerunning the application.

Figure 2

Figure 2

Meal Deal

Problem Description

A group of self-employed business associates often travel together and don’t want to be bothered splitting their food bills at every meal. During the trip they take turns paying the daily food bills. For example John may pay all the bills on Monday, Jane all the bills on Tuesday, and so on. When they return they have to determine who owes money so they all end up spending the same amount for food. You have been asked to automate this process.

Detailed Requirements

  1. Prompt for and read the number of travelers on a trip. This will be a positive integer greater than one ( > 1 ) and less than 100. (Sometimes a lot of people travel together!)
  2. Read the amount each person paid for food. This will be a floating point number greater than zero. It will have no upper limit except the maximum value that can be stored. Enter all the amounts on a single line separated by one space.
  3. Display the minimum amount of money that must change hands so that every traveler ends up paying the same amount. For example, assume four workers travel and have daily food bills of $10, $20, $30, and $40. This means traveler 1 must repay $15 and traveler 2 must repay $5 for a total that must be repaid of $20. We don’t care who the money goes to or who the money comes from; only the total amount that must be collected which is $20.
  4. Display the output rounded to two decimal positions.
  5. Add comments at the top of your source code for your name and the problem number.
  6. The judges will enter additional test data not provided below to further test your application. You don't need to validate the input. The judges will only enter valid data.

Output

Display a single numeric value representing the minimum amount that must change hands so that every traveler paid the same amount. The number of decimals in the output doesn’t need to be rounded.

Test Data

Number of TravelersDaily Food BillsOutput
4 10.00 20.00 30.00 40.00 20.00
3 10.00 20.00 30.00 10.00
5 1500.00 3.00 3.01 1500.01 255.34 1695.47
7 27.55 303.44 67.99 203.00 1998.00 234.66 3.50 1592.55
2 100.55 110.12 4.79

A sample console interface is provided below. Your user interface is not being judged. Each set of data can be tested by rerunning the application.

Enter the number of travelers:
5
Enter the daily meal costs:
1500.00 3.00 3.01 1500.01 255.34

1695.47

Figure 1

A sample graphical user interface is provided below. Your user interface is not being judged. Each set of data can be tested by rerunning the application.

Figure 2

Figure 2

Palindrome

Problem Description

A palindrome is a word that is the same forward as backward: “mom” and “bib” are examples. Positive integers can be palindromic. For example the numbers 3, 484, 12621, and 458854 are all palindromic. How many palindromic integers are there between x and y inclusive given that x will be > 0 and y will be <= 1,000,000?

Detailed Requirements

  1. You will enter an x value and a y value within the above constraints. The x value will be less that the y value. Each will be an integer. You do not need to edit these numbers.
  2. The application must calculate and display the number of palindromes within that range.
  3. Include x and y as potential palindromes. For example, if x = 343 and y = 6226 then the number of palindromes is at least two because x and y are both palindromes.
  4. Add comments at the top of your source code for your name and the problem number.
  5. The judges will enter additional test data not provided below to further test your application. You don't need to validate the input. The judges will only enter valid data.

Output

Display a single number indicating how many palindromes exist in the range for each test case. Format the output exactly as shown in the test data below.

Test Data

InputOutput
X valueY Value 
55 757 71
1 1000000 1998
11111 100000 889
1 100 18

A sample console interface is provided below. Your user interface is not being judged. Each set of data can be tested by rerunning the application.

Lower bound:
55
Upper bound:
75
The number of palindromes is 2

Figure 1

A sample graphical user interface is provided below. Your user interface is not being judged. Each set of data can be tested by rerunning the application.

Figure 2

Figure 2

Stacking Blocks

Problem Description

In this problem you will be given X number of blocks. You must programmatically determine the highest level to which the blocks can be stacked and how many blocks, if any, are left over. For example, with 3 blocks I can build a pyramid of 2 rows (2 levels) and have 0 left over as shown below.

Figure 1

With 8 blocks I can build a pyramid of 3 rows (3 levels) and have 2 left over.

Figure 2

Detailed Requirements

  1. Read the number of blocks. This will be an integer value greater than zero ( > 0 ) and less than largest size an integer can be.
  2. Determine the highest level to which the blocks can be stacked and how many blocks are left over.
  3. Display the level and the number of blocks left over.
  4. Add comments at the top of your source code for your name and the problem number.
  5. The judges will enter additional test data not provided below to further test your application. You don't need to validate the input. The judges will only enter valid data.

Output

For each test case display a single line indicating the highest level possible and the number of blocks left over. Format the output exactly as shown in the test data below.

Test Data

InputOutput
1 1 level(s) with 0 block(s) left over
8 3 level(s) with 2 block(s) left over
1500 54 level(s) with 15 block(s) left over
1000000 1413 level(s) with 1009 block(s) leftover

Your user interface is not being judged. Each set of data can be tested by rerunning the application.

Number of blocks:
1500
54 level(s) with 15 block(s) leftover

Figure 3

A sample graphical user interface is provided below. Your user interface is not being judged. Each set of data can be tested by rerunning the application.

Figure 4

Figure 4

Gather Points

Problem Description

The goal of this exercise is to navigate through an array accumulating “points”. You can only move forward (to the right or down). Diagonal moves are not allowed. You enter the array at the top left corner and exit at the bottom right corner. You must always move to the next square with the largest value. The array will be of various sizes and the values will be given to you. You will not encounter a choice between two numbers that are equal. One choice will always be greater than the other.

Figure 1

The path accumulating the most points is highlighted below.

Figure 2

The total points accumulated are 37. This is based on the following:

  1. Add 5 from starting point. Then “move” right or down to the larger of 6 or 8.
  2. Accumulate 8 by “moving” to that square.
  3. Then “move” to the larger of 2 or 10.
  4. Accumulate 10 by “moving” to that square.
  5. Continue the process arriving at a total of 37.

If we repeat the same process on another sample array below we arrive at a total number of 51 accumulated points.

Figure 3

The points accumulated were calculated based on the following “path” through the array: 3 + 7 + 10 + 8 + 9 + 5 + 9 = 51.

Detailed Requirements

  1. Only integers will exist in the array. The array will not necessarily have the same number of rows and columns but it will always be rectangular. You may hard code the array - no user input is required.
  2. The array will never have a combination where the choice where to move will be between two equal numbers. One move will always have more points than an alternative move.
  3. Add comments at the top of your source code for your name and the problem number.
  4. The judges will use additional test data not provided below to further test your application.

Output

Display a single number that is the maximum sum of the digits representing a path from the upper left corner to the lower right corner.

Test Data

Test Data

You Are It

Problem Description

Kids at a birthday party want to play a favorite game modeled after the game of tag. Unfortunately it is raining so they can’t go outside. They can’t run in the house so you decide to write a computer application to simulate the game. In the game the children sit in a circle and one person outside the ring (the leader) sings a song with a fixed number of words. Moving clockwise around the circle, the leader points to a new child in the ring for each word in the song. The child being pointed to on the last word of the song is out and must leave the circle. The leader then repeats the process with the smaller circle. The game continues until the last child is eliminated. This child is then the leader to start the next game.

Detailed Requirements

  1. Read an integer value representing the number of kids who will be playing the game. The number will be greater than one and less than 1001.
  2. Read an integer value representing the number of words in the song. The number will be greater than one and less than the maximum size an integer can store.
  3. Display the list, in order, of the players eliminated.
  4. Add comments at the top of your source code for your name and the problem number.
  5. The judges will enter additional test data not provided below to further test your application. You don't need to validate the input. The judges will only enter valid data.

Output

Display a single line indicating the order of players eliminated. Separate each number by a single space.

Test Data

Number of KidsWords in SongOutput
11 4 4 8 1 6 11 7 3 2 5 10 9
6 3 3 6 4 2 5 1
25 8 8 16 24 7 17 1 11 21 6 19 5 20 10 25 15 12 4 3 9 14 23 22 13 2 18
4 5 1 3 4 2
10 12 2 5 9 6 4 8 7 3 1 10

A sample console interface is provided below. Your user interface is not being judged. Each set of data can be tested by rerunning the application.

Enter number of kids:
6
Enter number of words in song:
3
3 6 4 2 5 1

Figure 1

A sample graphical user interface is provided below. Your user interface is not being judged. Each set of data can be tested by rerunning the application.

Figure 2

Figure 2

The Snail in the Well

Problem Description

A snail is at the bottom of a well and wants to climb to the top. The snail can climb X feet while the sun is up, but slides down Y feet at night while sleeping. The snail has a fatigue factor of F%, which means that on each successive day the snail climbs F% feet less than it did the previous day. The distance lost to fatigue is always F% of the first day's climbing distance. Given the height of the well, X, Y, and F, on what day does the snail leave the well? An alternative fate is the snail will not be able to climb out of the well and slides back to the bottom. In that case you will need to determine the day when the snail returns to the bottom of the well. Consider the example below.

Height of well = 6; X (distance climbed the first day) = 3; Y (distance slipped each night) = 1; F (fatigue percent) = 10

Day Initial Height Distance Climbed Height After Climbing Height After Sliding
1 0' 3' 3' 2'
2 2' 2.7' 4.7' 3.7'
3 3.7' 2.4' 6.1' -

Example 1

The snail’s height on the third day (6.1 feet) exceeds the height of the well (6 feet) and this indicates it has climbed out of the well.

Another example demonstrates the snail failing back to the bottom.

Height of well = 1; X (distance climbed the first day) = 1; Y (distance slipped each night) = 1; F (fatigue percent) = 1.

Day Initial Height Distance Climbed Height After Climbing Height After Sliding
1 0' 1' 1' 0'
2 0' 0.99' 0.99' -0.01'

Example 2

The snail’s height on the second day (-0.01 feet) is negative and this indicates it has slid back to the bottom of the well.

  1. A day consists of a period of sunlight followed by a period of darkness.
  2. The snail escapes the well when its height exceeds the height of the well.
  3. The snail hits the bottom of the well again when its height becomes negative (< 0).
  4. Input will consist of four integer numbers separated by a single space. Each number will be greater than 0 and less than 101. The first number will be the height of the well. The second number will be how far the snail climbs on the first day. (The snail will never climb a negative distance.) The third number will be how far the snail slips each night. The fourth number will be “fatigue factor”.
  5. All the numbers input will be considered to be in feet.
  6. The fatigue factor is used to determine how much the snail’s climbing ability is reduced. The reduction amount is the same for each day and is based on the climbing distance of the first day. In the example 1 above, the fatigue factor is 10. This means the snail will climb .3 feet less each day. This is calculated as the first day climbing distance (3 feet) times 10 percent.
  7. If the fatigue factor drops the snail's climbing distance below zero, the snail does not climb at all that day.
  8. The snail always slides the same amount at night regardless of how far it has climbed during the day.
  9. The snail never climbs a negative distance. If the fatigue factor drops the snail's climbing distance below zero, the snail does not climb at all that day.
  10. The snail leaves the well when the height it has climbed exceeds the height of the well. Your solution should print “Success on day X” where X represents the numerical count of the days.
  11. The snail hits the bottom of the well again when its height becomes negative (< 0). Your solution should print “Failure on day X” where X represents the numerical count of the days.
  12. Add comments at the top of your source code for your name and the problem number.
  13. The judges will enter additional test data not provided below to further test your application. You don't need to validate the input. The judges will only enter valid data.

Output

For each test case display a single line indicating whether the snail succeeded (left the well) or failed (slid back to the bottom) and on what day. Format the output exactly as shown in the test data below.

Test Data

Height of WellInitial Climbing DistanceSliding DistanceFatigue FactorOutput
6 3 1 10 Success on day 3
10 2 1 50 Failure on day 4
50 5 3 14 Failure on day 7
50 6 4 1 Failure on day 68
50 6 3 1 Success on day 20
1 1 1 1 Failure on day 2

A sample console interface and a graphical user interface are provided below. Your user interface is not being judged. Each set of data can be tested by rerunning the application.

Figure 1

Figure 1

Figure 2

Figure 2

Samples from the 2012 Programming Contest

Expand all samples | Contract all samples

UPC Check Digit

Problem Description

The most common form of Universal Product Code (UPC) is UPC-A which has 12 digits arranged to make a unique number. The twelfth digit is a check digit calculated based on the values in digits one through eleven. Calculate a UPC-A check digit given the eleven digits.

Detail Requirements

  1. Read eleven single digit numbers. You must enter these as one complete “number” and not as individual digits or characters. This means you must enter the digits and press the enter key once to have your application read the entire “number” if you are using a console application. You cannot enter each digit individually and click a button to process it if you are using a graphical user interface. Enter all the digits and then click the process button once.
  2. Only numbers will be entered as test data. No letters, spaces, or special characters will be entered.
  3. To calculate the check digit:
    1. Add the digits in the odd numbered positions (first, third, fifth, …).
    2. Multiply the above sum by three.
    3. Add the digits in the even numbered positions (second, fourth, sixth, …) to the total from above.
    4. Find the remainder when you divide the result by ten.
    5. The check digit is zero if the remainder is zero. Otherwise subtract the remainder from ten to get the check digit.
  4. Display the original “number” and the check digit.
  5. Add comments at the top of your source code for your name and the problem number.
  6. The judges will enter additional data not provided above to further test your application. Only valid numbers will be entered as test data. Each set of test data can be tested by rerunning the application.
  7. A sample console interface is provided below. Your user interface is not being judged. Each set of data can be tested by rerunning the application.
    Enter the UPC code minus the check digit: 01600027559
    Check digit for 01600027559 is 1
  8. A sample graphical user interface is provided below. Your user interface is not being judged. Each set of data can be tested by rerunning the application.
    Screenshot of the gui for getting the check digit

    Test Data


    Input Output
    01600027559 Check digit for 01600027559 is 1
    74953850500 Check digit for 74953850500 is 6
    40010068896 Check digit for 40010068896 is 0

Number Sequences

Problem Description

A numeric sequence is a series of numbers in which the relation of a number to the one that follows it is the same. For example, 1, 2, 3, 4 and 3, 6, 12, 24 are both sequences. In the first sequence each number is one less than the one that follows it. In the second sequence, each number is one-half the one that follows it. Two types of numerical sequences are arithmetic and geometric. The first sequence is arithmetic because each number differs from its predecessor by the same value - in this case 1. The second sequence is geometric because each number differs from its predecessor by the same multiplication factor - in this case 2.

The term for a sequence is the value at any given location. Given the sequence 3, 6, 12, 24, the first term is 3, the third term is 12, and the fifth term would be 48.

Determine whether a list of numbers is a sequence (arithmetic or geometric) and the type. Determine the value of the Nth term if the list is a sequence.

Detail Requirements

  1. Prompt the user to enter a maximum of 10 numbers. The user can signify the end of data entry before 10 numbers by entering 99999. Display an error and end the application if fewer than three numbers are entered.
  2. Prompt the user to enter an integer number (N) for the Nth term in the sequence.
  3. Determine if the list of numbers entered is an arithmetic sequence, a geometric sequence, or neither. Print one of the following:
    1. The list is an arithmetic sequence.
    2. The list is a geometric sequence.
    3. The list is not a sequence.
  4. Display the value of the Nth term if the list is a sequence.
  5. Add comments at the top of your source code for your name and the problem number.
  6. The judges will enter additional data not provided above to further test your application. Only integer numbers will be entered as test data. No letters, spaces, or special characters will be entered. Each set of test data can be tested by rerunning the application.
  7. A sample console interface is provided below. Your user interface is not being judged. Each set of data can be tested by rerunning the application.
    Enter up to 10 numbers:
    Number 1: 7
    Number 2: 9
    Number 3: 11
    Number 4: 13
    Number 5: 15
    Number 6: 99999
    Enter N for the ninth term: 27
    The list is a(n) arithmetic sequence
  8. A sample graphical user interface is provided below. Your user interface is not being judged. Each set of data can be tested by rerunning the application.
    Numeric Sequences

Diminishing Area

Problem Description

A series of right triangles can be inscribed (nested) within each other as shown in the figure below. The original right triangle has three smaller triangles nested inside. The area of each nested triangle obviously decreases as it gets smaller. The goal is to determine the area of the right triangle nested at a specific level.

Figure showing nested righ-angle trianbles

The area of a right triangle is ½ (base * height). The height for a right triangle is the line perpendicular to the base. In the outer triangle above, the base is b and the height is a. The sides of each nested triangle are ½ the length of its parent triangle. For example, if a = 30, b = 40, and c = 50 then the equivalent sides for the first nested triangle are 15, 20, and 25 respectively. You are given a set of three (x,y) coordinates for an outer triangle. You are also given the number of nested triangles. Use this information to determine the area of the triangle at that level.

A Cartesian coordinate system is used as displayed below. The 3 (x,y) coordinates for the given right triangle are (-7,5), (-7,-5), and (5,-5).

Graph
  1. Accept three sets of x,y coordinates representing the points of a right triangle.
  2. The coordinates are guaranteed to form a right triangle when lines are drawn between them. The coordinate pairs must be entered one number at a time. See the sample user interface below.
  3. The base of the triangle is always parallel to either the X or Y axis.
  4. Accept a number representing how many levels of nesting must occur.
  5. Display the area of the right triangle at that level.
  6. Add comments at the top of your source code for your name and the problem number.
  7. The judges will enter additional data not provided above to further test your application. Only integer numbers will be entered as test data. No letters, spaces, or special characters will be entered. Each set of test data can be tested by rerunning the application.
  8. A sample console interface is provided below. Your user interface is not being judged. Each set of data can be tested by rerunning the application.

    Enter x1:5
    Enter y1:5
    Enter x2:45
    Enter y2:5
    Enter x3:5
    Enter y3:35
    Enter how many nested triangles doyou want: 3
    The areofnested triangle 3 is 9.375
  9. A sample graphical user interface is provided below. Your user interface is not being judged. Each set of data can be tested by rerunning the application.

    Screen shot of the interface
Test Data for Diminishing Space

Foreign Language

Problem Description

Derwin is trying to convince his teacher that Pig Latin is an appropriate foreign language. He says he speaks and writes Pig Latin fluently. He also informs his professor that none other than Thomas Jefferson used to write his friends in Pig Latin. Derwin’s professor, always a good sport, plans to translate all Derwin’s assignments for the rest of the semester into Pig Latin but needs help. You will help by writing an English to Pig Latin translation program.

Detail Requirements

  1. Read a sentence from the console. The sentence will end with the “word” zzzzz. The zzzzz is a marker indicating the end of the input. Do not translate it to Pig Latin.
  2. Replace each English word with its Pig Latin equivalent. There are two basic rules.
    1. Add “way” to the word if it starts with a vowel (a, e, i, o, u). The English word “each” becomes the Pig Latin word "eachway".
    2. If the word doesn’t start with a vowel, take all the consonants from the beginning of the word up to (but not including) the first vowel. Move these to the end of the word. Add "ay". The English word "brick" becomes the Pig Latin word "ickbray".
  3. Keep the u with the q in words with the "qu" combination. The English word "quit" becomes the Pig Latin word itquay. We will ignore the few English words that have a q but no following u. Also you can assume that the qu combination will always be followed by a vowel. There will never be more than one letter q in a word.
  4. The letter y is normally considered a consonant except when there are no vowels in the word like "try". Treat the y as a vowel in this case and follow the rules of 2b. The English word "try" would become the Pig Latin word "ytray".
  5. Maintain the proper case of the word. The Pig Latin word must be uppercase if the English word begins with an uppercase letter. The English word Floridian would be Oridianflay. The phrase:
    Go to School John.zzzzz
    Would translate as:
    Ogay otay oolschay ohnjay Notice the capitalization of the Ogay and Ohnjay.
  6. Punctuation marks will only occur at the end of words and must be reproduced at the end of the respective Pig Latin word. The phrase:
    John, it is time to leave! zzzzz
    Would translate as:
    Ohnjay, itway isway imetay otay eavelay!
  7. Add comments at the top of your source code for your name and the problem number.
  8. The judges will enter additional data not provided above to further test your application. Only letters, spaces and punctuation will be entered as test data. A single space will separate each word. Each set of test data can be tested by rerunning the application.
  9. A sample console interface is provided below. Your user interface is not being judged. Each set of data can be tested by rerunning the application.

    Foreign Language screen shot

Test Data

Input 1
Derwin, here is your assignment for this week. Make sure you try all the problems! zzzzz

Output 1
Erwinday, erehay isway ouryay assignmentway orfay isthay eekway. Akemay uresay ouyay ytray allway ethay oblemspray!

Input 2
The assignment is not hard but you must start early. Do not delay. The quiz is Thursday. zzzzz

Output 2
Ethay assignmentway isway otnay ardhay utbay ouyay ustmay artstay earlyway. Oday otnay elayday. Ethay izquay isway Ursdaythay.

Samples from the 2011 Programming Contest

Expand all samples | Contract all samples

Scheduling Easter

Problem Description

Easter can occur as early as March 22nd and as late as April 25th. The problem is it moves around from year to year. The exact day of the year can be calculated based on a formula by the German mathematician Friedrich Gauss. Create an application to determine the date of Easter for any year between 1583 and 2299.

Detail Requirements

  1. Use the following calculations:

    a = year mod 19
    b = year mod 4
    c = year mod 7
    d = (19a + M) mod 30
    e = (2b + 4c + 6d + N) mod 7
    Figure 1
  2. The values for M and N are provided in the following table.

    YearMN
    1583-1699 22 2
    1700-1799 23 3
    1800-1899 23 4
    1900-2099 24 5
    2100-2199 24 6
    2200-2299 25 0
    Figure 2
  3. If d + e is less than 10 then Easter is on the d + e + 22 of March. Otherwise Easter is on the d + e – 9 of April. You must also incorporate the following exceptions:

    1. Easter can never be on April 26. If the calculated date is April 26, shift it to April 19.
    2. If the calculated date is April 25, with d = 28, e = 6, and a > 10 then Easter is on April 18.
  4. Print the day of the month using the proper ordinal suffix (st, nd, rd, th) after day of the month.

  5. Prompt the user to enter the year for which the date of Easter is to be calculated. Read the year. Use this input and the formula above to calculate the date for Easter. Below is sample input and output. Match the sample output exactly for the given sample input.

    Input YearOutput
    2011 In 2011 Easter is on April 24th
    1886 In 2011 Easter is on April 25th
    2222 In 2222 Easter is on March 31st
    1820 In 1820 Easter is on April 2nd
    1988 In 1988 Easter is on April 3rd
    Figure 3
  6. Add comments at the top of your source code for your name and the problem number.

  7. The judges will enter additional data not provided in the table above to further test your application. Only valid four digit years between 1583 and 2299 (inclusive) will be entered as test data.

  8. A sample console interface is provided below. Your user interface is not being judged. Each set of data can be tested by rerunning the application. It is not necessary to create a user controlled loop.

    Figure 4
    Figure 4 – Sample Console Interface

  9. A sample graphical user interface is provided below. Your user interface is not being judged.

    Figure 5
    Figure 5 – Sample Graphical User Interface

Binary Adder

Problem Description

Create an application that accepts a binary number and a decimal number as input. Add these numbers. Display the sum as a binary number.

Detail Requirements

  1. You may use the Calculator utility in Accessories on your PC.

  2. Only valid binary and decimal numbers will be entered.

  3. Decimal numbers will be in the range from 0 >= d <= 50,000.

  4. Binary numbers will be in the range from 0 >= b <= 50,000.

  5. Use the following data to test your application. Match the output exactly.

    Binary Number InputDecimal Number InputOutput (Sum in Binary Format)
    111 3 Binary sum is 1010
    110110 6 Binary sum is 111100
    11 5 Binary sum is 1000
    1010 10 Binary sum is 10100
    0111111111111111 2500 Binary sum is 1000100111000011
    Figure 1 – Test Input and Output
  6. The judges will enter additional data not provided in the table above to further test your application.

  7. Add comments at the top of your source code for your name and the problem number.

  8. You may use simple console input and output for this application. Each set of data can be tested by rerunning the application. It is not necessary to create a user controlled loop.

  9. A sample console interface is provided below. Your user interface is not being judged.

    Figure 2
    Figure 2 – Console Interface

  10. A sample graphical user interface is provided below.

    Figure 3
    Figure 3 – Graphical User Interface

  11. You must enter the binary number as one complete number and not as individual numbers or characters. This means you must enter the binary number and press the enter key once to have your application read the entire binary number if you are using a console application. You cannot enter each binary digit individually and press the enter key after each. Likewise in a graphical user interface application, you cannot enter each binary digit individually and click a button after each.

Pythagoras Redux

Problem Description

The Pythagorean Theorem states that a2 + b2 = c2. The most well known combination is 3, 4, and 5 since 32 + 42 = 52. Find all combinations of a, b, and c that fit this theory given a, b, and c must each be less than or equal to a maximum number entered by the user.

Detail Requirements

  1. Prompt the user for a maximum value. The value will be an integer and not exceed 500.

  2. The value of “a” cannot exceed the user supplied maximum. The value of “b” cannot exceed the user supplied maximum. The value of “c” cannot exceed the user supplied maximum.

  3. Determine and print all combinations of a, b, and c such that the following are true:

    2 <= a <= user entered maximum
    2 <= b <= user entered maximum
    2 <= c <= user entered maximum
    a2 + b2 = c2

  4. Do not print duplicates. That is 3, 4, 5 is valid but 4, 3, 5 is a duplicate. 6, 8, 10 is valid but 8, 6, 10 is a duplicate.

  5. Do not print any combination that has “a” equal to zero or “b” equal to zero.

  6. Print “a” then “b” and then “c” in your output as a heading. Then print each combination of a, b, and c on its own line. Separate each number by two blank spaces. The sample output for 10 is:

    a  b  c
    3  4  5
    6  8  10

    You do not need to “align” the columns. See the sample output in Figure 2.

  7. The output you should receive for various maximums are listed below.

    Maximumabc
    20 3 4 5
    5 12 13
    6 8 10
    8 15 17
    9 12 15
    12 16 20
    10 3 4 5
    6 8 10
    50 3 4 5
    5 12 13
    6 8 10
    7 24 25
    8 15 17
    9 12 15
    9 40 41
    10 24 26
    12 16 20
    12 35 37
    14 48 50
    15 20 25
    15 36 39
    16 30 34
    18 24 30
    20 21 29
    21 28 35
    24 32 40
    27 36 45
    30 40 50
    Figure 1 – Sample Input and Output
  8. The judges will enter a different maximum than those specified above to further test your application.

  9. Add comments at the top of your source code for your name and the problem number.

  10. You may use the Calculator utility in Accessories on your PC.

  11. A sample console interface is provided below. Your user interface is not being judged. The sample output shows all valid values for “a”, “b”, and “c” not greater than 100. That is, a <= 100, b <= 100, and c <= 100.

    Figure 2
    Figure 2 – Sample Console Interface

Array Diagonals

Problem Description

Given the array below, calculate and display the total of the left diagonal sum and the right diagonal sum.

22 13 2 8 30
14 21 18 25 27
7 4 10 3 15
5 17 12 11 16
23 6 1 9 24
Figure 1 – Original Array

Detail Requirements

  1. The user will enter an integer value. All numbers will be in the range 0 > n < 100.

  2. Display an error message if the value entered doesn’t exist in the array. Otherwise display the sum of the left and right diagonals of the array. Format your output exactly as shown below.

    InputOutput
    21 The sum of the diagonals for 21 is 97
    17 The sum of the diagonals for 17 is 113
    3 The sum of the diagonals for 3 is 95
    66 That diagonal doesn’t exist.
    27 The sum of the diagonals for 27 is 56
    Figure 2 – Test Input and Output
  3. The left diagonal sum is the sum of all the numbers running from the matching input number to the upper left/top edge of the array and to the lower right/bottom edge of the array. For example, if 17 is entered the left diagonal sum is 25 (17 + 1 + 7) as shown below.

    22 13 2 8 30
    14 21 18 25 27
    7 4 10 3 15
    5 17 12 11 16
    23 6 1 9 24
    Figure 3 – Left Diagonal for 17
  4. The right diagonal sum is the sum of all the numbers running from the matching input number to the upper right/top edge of the array and to the lower left/bottom edge of the array. For example, if 17 is entered the right diagonal sum is 105 as shown below (17 + 10 + 25 + 30 + 23).

    22 13 2 8 30
    14 21 18 25 27
    7 4 10 3 15
    5 17 12 11 16
    23 6 1 9 24
    Figure 4 – Right Diagonal for 17
  5. The sum of the diagonals for 17 is 113. This is calculated as the left diagonal plus the right diagonal but the diagonal value itself (17) is only counted once.

  6. If 2 is entered, the left diagonal sum is 42 as shown below (2 + 25 + 15)

    22 13 2 8 30
    14 21 18 25 27
    7 4 10 3 15
    5 17 12 11 16
    23 6 1 9 24
    Figure 5 – Left Diagonal for 7
  7. If 2 is entered, the right diagonal sum is 30 as shown below (2 + 21 + 7).

    22 13 2 8 30
    14 21 18 25 27
    7 4 10 3 15
    5 17 12 11 16
    3 6 1 9 24
    Figure 6 – Right Diagonal for 7
  8. The sum of the diagonals for 2 is 70. This is calculated as the left diagonal (42) plus the right diagonal (30) but remember the diagonal value itself (2) is only counted once.

  9. A number will occur in the array only once.

  10. Remember the number input by the user must only be included in the sum once.

  11. In addition to using the test data, the judges will also change the array values given in Figure 1 and test with new input values not provided to you.

  12. Add comments at the top of your source code for your name and the problem number.

  13. A sample console interface is provided below. Your user interface is not being judged. Each set of data can be tested by rerunning the application. It is not necessary to create a user controlled loop.

    Figure 7
    Figure 7 – Sample Console Interface

  14. A sample graphical user interface is provided below. Your user interface is not being judged.

    Figure 8
    Figure 8 – Sample Graphical User Interface

Samples from the 2006 Programming Contest

Expand all samples | Contract all samples

Binary Operators

Problem Description

Read two lists of integers. Compare the lists using the AND, OR, XOR and NOR operations.

Input/Output

Your application should prompt and read a maximum of 10 digits. The digits will be in the range of 0 to 9. The user will enter a -1 to end the list if less than 10 numbers are entered. Separate each number entered by a space. Once the first list is entered, repeat the process for a second list of integers. The second list can be the same length, longer or shorter than the first list. Each list can have any combination of the numbers 0 through 9. Each list must have at least one number.

Once both lists are entered, apply each of the follow operations to the lists:

OperationDescription
AND Print all numbers that occur in both lists. These are the numbers the lists have in common.
OR Print all numbers that occur in either list.
XOR Print all numbers that occur in one list but not the other.
NOR Print all numbers that are not in either list.

Sample Input 1:

8 3 7 1 -1

1 2 3 4 5 6 7 8 9 0 -1

Output 1:

A  OR  B  =  0 1 2 3 4 5 6 7 8 9

A  NOR  B  =

A  AND  B  =  1 3 7 8

A  XOR  B  =  0 2 4 5 6 9

Sample Input 2:

0 -1

3 2 8 -1

Output 2:

A  OR  B  =  0 2 3 8

A  NOR  B  =  1 4 5 6 7 9

A  AND  B  =

A  XOR  B  =   0 2 3 8

Word Rectangle

Problem Description

Read a single word and print the word as a rectangle. The word will be a maximum of 40 characters long and a minimum of two characters long.

The format of the rectangle will be:

  1. The word will read left to right when starting from the upper-left corner of the rectangle.
  2. The word will read top to bottom when starting from the upper-left corner of the rectangle.
  3. The word will read bottom to top when starting from the lower-right corner of the rectangle.
  4. The word will read right to left when starting from the lower-right corner of the rectangle.

Input/Output

Your application should accept a single word input from the keyboard. The word will be a maximum of 40 characters long and a minimum of two characters long. Print the word in the format described below. Stop the application after printing the word rectangle.

Sample Input/Output

Sample Input 1:

bookstore

Sample Output 1:

bookstore
o       r
o       o
k       t
s       s
t       k
o       o
r       o
erotskoob

Sample Input 2:

it

Sample Output 2:

it
ti

Amazing Numbers

Problem Description

Find all numbers that, when multiplied by 365, produce an eight-digit product where the first four digits of that product are equal to the last four digits of that product. For example, 271123 x 365 produces an eight-digit product (98959895) whose first four digits (9895) are equal to its last four digits (9895).

Input/Output

There is no input for this problem.

The output will be a list of the first 10 integers that, when multiplied by 365, create an eight-digit product where the first four digits of that product are equal to the last four digits of that product. Also, print the product of the number and 365. Submit a second version of your application that prints all of the numbers (not just the first 10) so the judges can see the last 10 numbers generated.

Sample Output

Output for a single random combination is listed below.

Number        Number * 365

......        ........

271123        98959895

......        ........

Roman Numerals

Problem Description

Create an application that converts Arabic base 10 numbers into Roman numerals.

Input/Output

Your application should accept a single integer value input from the keyboard. This number will be in the range from 0 to 2000. Convert the number entered to its Roman numeral equivalent if the numbered entered is greater than zero. After converting to and displaying the Roman numeral, prompt the user to enter another number. Repeat these steps as long as the user enters an integer greater than zero.

End the application when the user enters a zero for the number to convert.

The highest number you must convert is 2000.

Your output will be the Roman numeral equivalent to the Arabic number entered. Each Roman numeral "letter" should be displayed in upper case. Below are the Roman numeral symbols you will use and some conversion rules.

Arabic NumberRoman Number
1 I
5 V
10 X
50 L
100 C
500 D
1000 M
  1. Generally, a string of Roman numerals indicates adding the values. For example, CLX would be 100 + 50 + 10, or 160. Notice that each Roman numeral is preceded by a Roman numeral that represents a larger value: L is larger than X, and C is larger than L. Placing a smaller Roman number in front of a larger Roman numeral indicates subtraction. For example, IV means 1 - 5, or 4.
  2. No more than three of the same Roman numeral may be used sequentially. For example, the Roman numeral for 8 is VIII, but the Roman numeral for 9 is IX, not VIIII. VIIII can't be used because it requires the symbol I to be used four times sequentially.
  3. You can subtract I, X, L, C or D, but not V.
  4. Subtract only a single Roman numeral from a single Roman numeral. For example, 8 is VIII not IIX. You can't subtract II from X because II is two Roman numerals, not one.
  5. Don't subtract a letter from another letter more than 10 times greater than itself. For example, the Roman numeral I can be subtracted from V or X only. X can be subtracted from X or L only.

Sample Input/Output

Your application must provide the following results for the given input. Your output must be formatted as indicated in the Output column below.

InputOutput
2000 MM
1996 MCMXCVI
592 DXCII
1091 MXCI
1886 MDCCCLXXXVI
Samples from the 2005 Programming Contest

Expand all samples | Contract all samples

Triangles

Problem Description

Create a program that reads three integer numbers. Each of these numbers represents one side of a triangle. The program must determine if lines of these three lengths could be used to create a triangle. If a triangle could be created, the program must further determine if that triangle would be an equilateral triangle, an isosceles triangle, a right triangle or a regular triangle.

Assume three lines can make a triangle if the sum of the lengths of the two shorter lines is greater than or equal to the length of the longest line. For example, you can make a triangle given lines of lengths 5, 3 and 7 because 5 + 3 is greater than 7. However, you cannot make a triangle with lines of lengths 3, 5 and 9 because 3 + 5 is less than 9.

If the lines can make a triangle, determine if the triangle is an equilateral triangle, an isosceles triangle, a right triangle or a regular triangle. An isosceles triangle is one in which two of the three sides are equal and the conditions above are met. An equilateral triangle is one in which all three sides are equal and the conditions above are met. A right triangle is one in which the sum of the squares of two sides equals the sum of the square of the third side and the conditions above are met. For example, a triangle with side lengths of 3, 4 and 5 is a right triangle because 32 + 42 = 52.

Input

Three positive integer values representing the three sides of a triangle will be entered. You do not need to edit to ensure that only numbers are entered. You may request the input be entered at one time or use three separate prompts — one for each input value. The values for the line lengths can be entered in any order. For example, you can't assume that the longest length will always be entered first, nor can you assume that the lengths will always be entered in descending or ascending order.

Your values may be input as a single set of data or as a grouping of three individual pieces of data. Your application can be created to process a single set of data. That is, after processing a set of data, your application can end. You can then start the application again and enter a second set of data. If you use a graphical interface (Visual Basic, C#, etc.), you can enter the data in text boxes and display the results in text boxes or labels. However, a graphical interface is not required for this application. If you create a command line application, you can prompt for the input numbers one at a time or enter them all in a single input statement.

Sample Input/Output

InputOutput
3  4  5 Right triangle
3  5  3 Isosceles triangle
2   10   2 Not a triangle
3   3   3 Equilateral triangle
5   10   20 Not a triangle
10   0   5 Not a triangle
7   14   20 Regular triangle

Ciphers

Problem Description

In this problem, each letter of the alphabet corresponds to a number using the scheme: a=1, b=2, c=3, ... y=25, z=26. To encode a message, an encryption key word is added to the message. The key word is the first word in the message that is five or more characters long. For example, if the message were:

"give me liberty or give me death," the key word would be "liberty." The encrypted message would be:

s r x j e y k u k g w l s n d p k a w g d p n c y z

The first letter, s, results from adding 7 for the letter "g" to 12 for the letter "l." The sum is 19, which creates the letter "s." The other letters are calculated in a like manner. The algorithm you develop should wrap around to the beginning of the alphabet if the sum of two letters exceeds 26. For example, when the letter "l" (12) is added to "y" (25), the sum is 37. Since there is no 37th letter in the alphabet, you should subtract 37 from 26 to get the number 11, which equates to the letter "k."

The key word is repeated indefinitely to the end of the message. For example:

give me liberty or give me death
libe rt ylibert yl iber ty liber
--------------------------------
srxj ey kukgwls nd pkaw gd pncyz

(Spaces are left between the words in this example for clarity. Do not include spaces in your results.)

Every message will have at least one five-letter word.

Spaces are not encrypted and not included in the output. Only messages in lowercase letters will be entered. No punctuation or special characters will be entered.

Input/Output

When encrypting, the input will consist of a sentence or phrase entered via the standard input device. The output must be the key and the encrypted message. Only lowercase letters will be entered, so it is not necessary to edit the input.

A text file will be provided with the sentences and phrases displayed below. You can copy and paste these for testing purposes to save time. They do not constitute the complete set of testing data the judges will use.

Your application can be created to process a single set of data. That is, after processing a set of data, your application can end. You can then start the application again and enter a second set of data. If you use a graphical interface (Visual Basic, C#, etc.), you can enter the data in text boxes and display the results in text boxes or labels. However, a graphical interface is not required for this application.

Sample Input/Output

Input PhraseKeywordEncrypted Output
a stitch in time saves nine stitch t m c c w k a c w n l u x m j p h a g c w y
it is a rainy day rainy a u r g z j b r b x v b h
it only hurts when i laugh hurts q o g h e g c m l m a r z y g q g s o z p
jack and jill went to the hills hills r j o w t v m v u e t f q z m b x f t x p r x x l

Delete Duplicates

Problem Description

Create an application that removes duplicate entries from a list of numbers. Your application will process a maximum of 20 integer numbers. Each number will be equal to or greater than zero. You do not need to edit for floating point numbers or invalid characters. Twenty is the maximum number of values to be entered. The user must be able to enter 0 numbers, 1 number, 20 numbers or any amount between 1 and 20. If you create a command-line application, allow the user to enter -1 to indicate that no more numbers will be entered. Once the input is complete, the application must indicate which numbers are duplicated and how many duplicates existed for each number.

Input

Input will be a series of integers separated by at least one space. Any number of integers from 0 to 20 may be entered. The user must be able to enter 0 numbers, 1 number, 20 numbers or any other count of numbers between 0 and 20 inclusive. You do not need to edit to ensure that only numbers are entered. Only integer numbers will be entered.

Your values may be input as a single set of data or as a grouping of individual pieces of data. Your application can be created to process a single set of data. That is, after processing a set of data, your application can end. You can then start the application again and enter a second set of data. If you use a graphical interface (Visual Basic, C#, etc.), you can enter the data in text boxes and display the results in text boxes or labels. However, a graphical interface is not required for this application. If you create a command-line application, you can prompt for the input numbers one at a time or enter them all in a single input statement.

Output

Print the original list of numbers entered. Next, print a list of any numbers that were duplicated and the number of duplicates. Finally, print the revised list of numbers minus any duplicates.

Sample Input/Output

InputOutput
1 2 3 4 5 1 6 1 7 1 8 1 9 1 10 -1 1 2 3 4 5 1 6 1 7 1 8 1 9 1 10

Value 1: 5 copies are deleted

1 2 3 4 5 6 7 8 9 10
1 2 1 2 1 2 1 2 3 4 5 3 -1 1 2 1 2 1 2 1 2 3 4 5 3

Value 1: 3 copies are deleted

Value 2: 3 copies are deleted

Value 3: 1 copies are deleted

1 2 3 4 5
23 23 23 23 23 23 23 -1 23 23 23 23 23 23 23

Value 23: 6 copies are deleted

23
8 7 33 19 22 57 -1 8 7 33 19 22 57

No duplicate values

8 7 33 19 22 57
18 -1 18

No duplicate values

18
-1 No duplicate values

The last row in the table above indicates that no values were entered.

Time Segments

Problem Description

Create an application that correctly calculates time segments. A segment of time can be represented as a number of days (d), a number of hours (h), a number of minutes (m) and a number of seconds (s). For example, a valid time segment would be:

12 days, 6 hours, 5 minutes and 49 seconds.

Valid output values for each component of time are as follows:

  • days (d) > 0
  • hours (h) > 0 and < 24
  • minutes (m) > 0 and < 60
  • seconds (s) > 0 and < 60

The input values for the time segments will not conform to the above rules. The application must determine invalid values and convert them to valid values. For example, the time segment:

23 30 45 93

indicates that days = 23, hours = 30, minutes = 45, and seconds = 93. The equivalent valid time segment would be:

24 days, 6 hours, 46 minutes and 33 seconds.

This is based on 93 seconds being converted to 1 minute and 33 seconds. The one minute is added to the input value of 45, resulting in 46 minutes. The input value of 30 hours is converted to one day (24 hours) and 6 hours. The one day is added to the input value of 23, resulting in 24 days.

Consider a second example below:

0 105 99 120

This example indicates 0 days, 105 hours, 99 minutes and 120 seconds. The equivalent valid time segment would be:

4 days, 10 hours and 41 minutes.

This is based on 120 seconds being converted to 2 minutes, and 105 days being converted to 4 days and 10 hours. Note that there is no time segment for seconds because that would be 0. Omit any time segment if it would be zero.

There are 60 seconds in a minute, 60 minutes in a hour and 24 hours in a day.

Input/Output

Input for this application will be a series of four integer values representing, in order, the days, hours, months and seconds as described above. However, the input values for d, h, m and s can be any integer value equal to or greater than zero. You do not need to edit to ensure that only numbers are entered. Only positive integer numbers will be entered.

The output will be a valid time segment in the format:

a days, b hours, c minutes and d seconds.

Omit any time segment if it would be zero.

Your values may be input as a single set of data or as a grouping of four individual pieces of data. Your application can be created to process a single set of data. That is, after processing a set of data, your application can end. You can then start the application again and enter a second set of data. If you use a graphical interface (Visual Basic, C#, etc.), you can enter the data in text boxes and display the results in text boxes or labels. However, a graphical interface is not required for this application. If you create a command-line application, you can prompt for the input numbers one at a time or enter them all in a single input statement.

Sample Input/Output

Your application must provide the following results for the given input. Your output must be formatted as indicated in the Output column below.

InputOutput
20 0 125 64 20 day(s), 2 hour(s), 6 minute(s), 4 second(s)
0 23 110 6000 1 day(s), 2 hour(s), 30 minute(s)
1 51 0 33 3 day(s), 3 hour(s), 33 second(s)
22 23 75 80 23 day(s), 16 minute(s), 20 second(s)
7 50 40 301 9 day(s), 2 hour(s), 45 minute(s), 1 second(s)

Want more info? Contact us.

Melinda White
Program Manager
Phone: 407.708.2447
Fax: 407.708.2322
Office: V102-I

Seminole State General Contact Information