Sample Questions from the 2011 Contest
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
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
The values for M and N are provided in the following table.
Year M N 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
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:
- Easter can never be on April 26. If the calculated date is April 26, shift it to April 19.
- If the calculated date is April 25, with d = 28, e = 6, and a > 10 then Easter is on April 18.
Print the day of the month using the proper ordinal suffix (st, nd, rd, th) after day of the month.
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 Year Output 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
Add comments at the top of your source code for your name and the problem number.
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.
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 – Sample Console InterfaceA sample graphical user interface is provided below. Your user interface is not being judged.
Figure 5 – Sample Graphical User Interface
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
You may use the Calculator utility in Accessories on your PC.
Only valid binary and decimal numbers will be entered.
Decimal numbers will be in the range from 0 >= d <= 50,000.
Binary numbers will be in the range from 0 >= b <= 50,000.
Use the following data to test your application. Match the output exactly.
Binary Number Input Decimal Number Input Output (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
The judges will enter additional data not provided in the table above to further test your application.
Add comments at the top of your source code for your name and the problem number.
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.
A sample console interface is provided below. Your user interface is not being judged.
Figure 2 – Console InterfaceA sample graphical user interface is provided below.
Figure 3 – Graphical User InterfaceYou 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.
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
Prompt the user for a maximum value. The value will be an integer and not exceed 500.
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.
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 = c2Do 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.
Do not print any combination that has “a” equal to zero or “b” equal to zero.
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 10You do not need to “align” the columns. See the sample output in Figure 2.
The output you should receive for various maximums are listed below.
Maximum a b c 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
The judges will enter a different maximum than those specified above to further test your application.
Add comments at the top of your source code for your name and the problem number.
You may use the Calculator utility in Accessories on your PC.
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 – Sample Console Interface
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
The user will enter an integer value. All numbers will be in the range 0 > n < 100.
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.
Input Output 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
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
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
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.
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
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
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.
A number will occur in the array only once.
Remember the number input by the user must only be included in the sum once.
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.
Add comments at the top of your source code for your name and the problem number.
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 – Sample Console InterfaceA sample graphical user interface is provided below. Your user interface is not being judged.
Figure 8 – Sample Graphical User Interface