#### Hawkeye Challenge Programming Competition 2016 Problems/Solutions

Division 1 (AP)

Problem 1. Roman Numeral Calculator

Your program should prompt the user to enter an equation with Roman numerals in it. It should return the answer as a Roman numeral. The prompt should be “QUOT? ”

The equation will only have positive numbers between 1 and 50, and the only operators will be addition (+) and subtraction (-). There may or may not be white space between the numbers.

A quick refresher of the rules for writing and reading Roman numerals may be helpful:

• 1=I, 5=V, 10=X, 50=L
• Repeated symbols are added (30=XXX), and are never repeated more than 3 times (40 is XL, not XXXX)
• Only I and X are repeated
• If one or more letters are placed after another letter of greater value, add that amount [VI=6, (5+1=6)]
• If a letter is placed before another letter of greater value, subtract that amount. [IV=4, (5-1=4)]
• Only subtract I or X (for 45, write XLV, not VL)
• Only subtract one number (for 13, write XIII, not IIXV)
• Do not subtract a number from one that is more than 10 times greater (you can subtract 1 from 10, but not 1 from 20. 19 is XIX, not IXX; 49 is XLIX, not IL)

Examples:

Input:

QUOT? IX + X – VIII

Output:

XI

Explanation: IX + X – VIII = 9 + 10 – 8 = 11 = XI

Input:

QUOT? L – XXX + XIII+ XIV + III – IV

Output:

XI

Explanation: L – XXX + XIII + XIV + III – IV = 50 – 30 + 13 + 14 + 3 – 4 = 46 = XLVI

Division 1 (AP)

Problem 2. Political Fever – Delegate Frenzy

Your program should read in a file called “election.txt”. The first line of the file will be the number of delegates to be awarded. The second line is a long string of votes, where each candidate is a letter. Using the Missituckychusets delegate rules described below, tell us how many delegates each candidate will be awarded.

Notes: Each candidate will always receive a whole number of delegates – no rounding should be necessary. Also, the output order of candidates does not matter.

Missituckychusets delegate rules:

1. If a candidate receives less than 15% of the total votes, they receive zero delegates and are considered non-viable.
2. If a candidate receives more than 50% of the total votes, they receive all of the delegates.

Examples:

Input file:

6

AAAABBBBCCCC

Output:

A: 2

B: 2

C: 2

Explanation: Since they each received 33% of the votes, each candidate receives 33% of 6 total delegates, which is 2. (Rule 3)

Input file:

12

AAAAAAABBBBBQQ

Output:

A: 7

B: 5

Q: 0

Explanation: Since A did not receive more than 50% of the votes, they receive a proportional amount of the viable votes. B receives 5 from proportionality. Q had less than 15% of the votes, so they were non-viable and got zero. (Rules 1, 3)

Input file:

10

AAAH

Output:

A: 10

H: 0

Explanation: Since A received more than 50% of the votes, they received all of the delegates. (Rule 2)

Division 1 (AP)

Problem 3. Fraud Detection

You are working for a bank that has decided to crack down on credit card fraud and you have been tasked with building a program to detect it. The bank wants the following to be flagged:

• Any transaction over 3000 dollars
• Two transactions by the same person, within 60 minutes of each other, in different locations.

To do this, your program should read in a file called “transactions.txt”. Each line of the file will be formatted like this:

person name|integer transaction amount|location|minutes since 00:00

Your program should go through the transactions looking for fraud, and then output a list of people whose credit card was used fraudulently. The order the names are listed in does not matter.

Examples:

Input file:

Tom|25|New York|1235

Ryan|3001|Iowa|1236

Output:

Ryan

Explanation: Ryan made a transaction that was greater than 3000 dollars.

Input file:

Tom|25|New York|4

Ryan|40|Iowa|40

Tom|40|Iowa|41

Output:

Tom

Explanation: Tom made two transactions, within 60 minutes of each other, in different locations.

Division 1 (AP)

Problem 4. Map Directions

Your program should read in a file called “map.txt”. The first line of the file will be a number between 4 and 100 (we’ll refer to it as K). The second line will be X and Y coordinates separated by spaces, each ranging from 1 to K. The third line will be a maximum number of steps. Following this, there will then be K lines of text, each with K characters. Each character will be N, S, E, or W, and this forms our map.

Your program should now simulate an explorer. Starting at the X,Y coordinates in the map (Y tells you which row of input, where 1 is the first row, and X tells you which character in that row, where 1 is the first character), start walking. If your explorer is on an N, their next step should go “up” when looking at the map from the text file. W will be “left” on the map, E will be “right,” and S will be “down.”

This should continue until one of two things happens:

• The explorer exits the map. In this case, tell us which edge they walked off and how many steps it took.
• You have taken the maximum number of steps and not exited. Tell us you were unable to exit.

Examples:

Input file:                                    Input file:

4                                              4

2 3                                            4 2

10                                             10

NSNW                                           ESNW

EESN                                           NWWW

SNEN                                           NSEN

NSEW                                           SSSS

Output:                                        Output:

Exited “N” after 8 steps                       Unable to exit after 10 steps

Explanation: Here is the map, with S           Explanation: Here is the map, with S

being the start location, and each             being the start location, and each

square numbered with which step the            square numbered with which step the

explorer was on.                               explorer was on.

--76                                           45--

-125                                           3215

-534                                           ----

----                                           ----

We started at 2,3, which was an N,             We started at 4,2. We then followed

went N, then E, S, W, N, N, N, W, N,           the map until we hit a loop (step 6

and then our 8th step was out the               would take us back to step 2), and

north side.                                    we continued walking until we hit 10

steps, and reported failure.

Division 1 (AP)

Problem 5. March Angry Frustrations (Please don’t sue us)

It was very recently March, which means we should make some brackets! You and your friends decided to have a programming tournament and need a way to make the brackets. Your program should take in a line of input, which will be comma-separated names. There may or may not be spaces before and after the comma. The program then will pair the names (the first two will be paired, next two paired, and so on). The winner of each game is decided by which name comes first in alphabetical order. Your program should output the games from each round until there is a winner.

Note: There will always be a power of two teams, and the formatting shown in the example output is important.

Example:

Input: John, Tom, Abby, Susan, Emily, Bobby, Kevin, Alex

Output:

(John, Tom), (Abby, Susan), (Emily, Bobby), (Kevin, Alex)

(John, Abby), (Bobby, Alex)

(Abby, Alex)

(Abby)

Division 2 (Non-AP)

Problem 1. Roman Numeral Translator

Your program should accept a number expressed using slightly modified Roman numerals as input and output the number as a decimal number. All numbers will be between 1 and 50.

Because real Roman numerals have so many small and complicated rules, we’ll be using a slightly modified form of Roman numerals – no subtraction. Here are the rules your program should use to read in the Roman numerals:

• I=1, V=5, X=10, L=50
• Repeated numerals are added (XX=20, III=3, XXXXVI=46)
• Only I and X can be repeated
• Each numeral will be less than or equal to the previous one (XVI=16 and is legal, XIV is not legal for this problem)

Examples:

Input: VIIII

Output: 9

Input: L

Output: 50

Input: XVI

Output: 16

Division 2 (Non-AP)

Problem 2. Political Fever – Delegate Frenzy

Your program should take in three inputs: The number of delegates, the percentage of votes Candidate 1 got, and the percentage of votes Candidate 2 got. Together with Candidate 3’s percentage (not given), all percentages should sum to 100. Using the Missituckychusets delegate rules described below, tell us how many delegates each candidate will be awarded.

Note: Each candidate will always receive a whole number of delegates – no rounding should be necessary.

Missituckychusets delegate rules:

1. If a candidate receives less than 15% of the total votes, they receive zero delegates and are considered non-viable.
2. If a candidate receives more than 50% of the total votes, they receive all of the delegates.
3. If a candidate receives between 15% and 50% (inclusive on both), they receive that percentage of all available delegates.
4. If a candidate is non-viable, their votes are split evenly among the other two candidates.

Examples:

Input: 10 .3 .3

Output:

Candidate 1: 3

Candidate 2: 3

Candidate 3: 4

Explanation: There are 10 delegates, Candidate 1 got 30%, and Candidate 2 got 30%, (which means Candidate 3 got 40%). Since there was no majority, each candidate receives their percentage of the 10 total delegates. (Rule 3)

Input: 40 .5 .4

Output:

Candidate 1: 22

Candidate 2: 18

Candidate 3: 0

Explanation: No candidate had a majority, so the delegates will be assigned proportionally. However, Candidate 3 was non-viable with 10%, so Candidates 1 and 2 each get an extra 5%. Delegates are then assigned proportionally to Candidates 1 and 2. 55% of 40 is 22, and 45% of 40 is 18. (Rules 1, 3, 4)

Input: 10 .75 .25

Output:

Candidate 1: 10

Candidate 2: 0

Candidate 3: 0

Explanation: Since Candidate 1 received more than 50% of the votes, they received all of the delegates.

Division 2 (Non-AP)

Problem 3. March Angry Frustrations (Please don’t sue us)

This year, one of the things that made people mad in March were the changes to the way buskerball game winners were decided. Rather than using the traditional way, in which the team that scores more points wins, the MCAA decided that these rules were more sporting:

• If the first letters of the team names are different, whichever team name comes first alphabetically wins.
• If the first letters are the same, whichever name is longer wins.

Your program should take in two team names, and output the winning team.

Example:

Input: Johnsonville, Bobbyston

Output: Bobbyston

Explanation: Bobbyston comes first alphabetically

Input: Iowa Hawkeyes, Indiana

Output: Iowa Hawkeyes

Explanation: Iowa Hawkeyes is longer

Division 2 (Non-AP)

Problem 4. Unambiguous Dates

Dates are tricky. Is 06/03/16 March 16, 2006? Or June 3, 2016? Or March 6, 2016? You can see the problem. Your program will be given three numbers in increasing order and it needs to say if they could represent a specific date, or if it could be multiple dates.

Examples:

Input: 7 15 32

Output: Unambiguous

Explanation: 32 can only be a year. With year taken, 15 can only be a day, leaving only 7 for the month.

Input: 7 15 31

Output: Ambiguous

Explanation: 31 could be a year or a day, and 15 could be a year or a day.

Input: 7 12 32

Output: Ambiguous

Explanation: 12 could be a month or a day, and 7 could be a month or a day.

Division 2 (Non-AP)

Problem 5. Fizz Buzz Woof

Your program should take a number N as input. It should then output the numbers from 1 up to N, inclusive. However, if a number is divisible by 3, it should instead output Fizz; if it is divisible by 5 it should output Buzz; and if it is divisible by 7, it should output Woof. If a number is divisible by 3 and 5; 3 and 7; 5 and 7; or 3, 5, and 7; it should output all relevant words, in the order of the problem title.

As a reminder, many languages support a modulus operator (Mod in Visual Basic, % in Python, Java, and most others) that tell you the remainder from dividing two numbers. Example: 12 % 5 = 12 Mod 5 = 2.

Examples:

Input: 8

Output:

1

2

Fizz

4

Buzz

Fizz

Woof

8

Input: 15

Output:

1

2

Fizz

4

Buzz

Fizz

Woof

8

Fizz

Buzz

11

Fizz

13

Woof

FizzBuzz