The Simplistic Primary Predictor predicts the winner of a state's primary election based on several factors:

The state that the candidate comes from

The region of the country the candidate comes from

The number of times a television commercial for the candidate has aired in that state

The number of days the candidate has spent campaigning in that state

The number of primary elections the candidate has won so far this year

The input to the program will be the name of a state (as a 2-letter abbreviation), followed by a list of information about each of several candidates. The information about each candidate will be:

A two-letter set of initials representing the name of the candidate

A two-letter state abbreviation, representing the home state of the candidate

An integer, representing the number of television commercials for the candidate that have aired in the current state.

An integer, representing the number of days that the candidate has spent campaigning in the state.

An integer, representing the number of primaries and caucuses the candidate has won so far this year

The program will compute a score for each candidate that attempts to predict the candidate's likelihood of success. The score is computed as follows: Begin with a score of 0. If the candidate's home state is the same as the current state, add 50 points. If the candidate's home state's region is the same as the current state's region, add 20 points. Add 1 for every 10 commercials that have aired. (Round down to the nearest integer: 37 commercials gives 3 points.) Add 1 for every day the candidate has spent campaigning in the state. Add 5 for every primary or caucus the candidate has won so far.

Use these regions in your calculations:

Region number Region Description States in Region

1 New England ME, NH, VT, MA, CT, RI

2 Northeast NY, PA, NJ, DE, MD

3 Southeast VA, NC, SC, GA, FL, AL, MS, TN, KY, WV, AR, LA

4 Lakes OH, MI, IN, IL, WI, MN

5 Central IA, MO, ND, SD, NE, KS, OK, TX

6 West MT, WY, CO, NM, AZ, UT, ID, NV

7 Pacific WA, OR, CA, AK, HI

The output will be a list of candidates' names and scores.

Disclaimer: While I have based the sample data below on some actual 2016 candidates, I have completely invented the numbers for commercials, campaign days, and wins so far. At the time of writing this document, there have not yet been any primary elections; the number of wins will, of course, change constantly throughout the primary season.

You are guaranteed that there will be at least one candidate in the input, and that there will be no more than 50 candidates.

Note: As you write your programs, try to implement the classification into regions as elegantly as possible. Try to avoid the 100-line solution, if you can:

if state = "ME" then

region = 1

elseif state = "NH" then

region = 1

...

end if;

Many languages at least permit the use of boolean operators:

if state = "ME" or state = "NH" or ... then

and some languages contain structures such as lists and sets that allow even more compact solutions.

Think about how to use the control constructs and data structures of your language to implement this classification process as elegantly as your language will allow.

Example 1:

Input:

NH

HC NY 78 21 1

MO MD 30 10 0

BS VT 93 15 0

Output:

HC 33

MO 13

BS 44

Explanation:

Candidate HC: 0 + 0 + 7 + 21 + 5*1 = 33

Candidate MO: 0 + 0 + 3 + 10 + 5*0 = 13

Candidate BS: 0 + 20 + 9 + 15 + 5*0 = 44

Example 2:

Input:

FL

12

JB FL 113 8 5

BC MD 163 9 3

CC NJ 95 4 3

TC TX 210 6 5

CF CA 40 1 0

JG VA 22 1 0

MH AR 25 2 0

JK OH 35 9 2

RP KY 13 2 0

MR FL 135 5 5

RS PA 38 2 0

DT NY 298 3 4

Output:

JB 94

BC 40

CC 28

TC 52

CF 5

JG 23

MH 24

JK 22

RP 23

MR 113

RS 5

DT 52

Explanation:

Candidate JB: 50 + 20 + 11 + 8 + 5*5 = 94

Candidate BC: 0 + 0 + 16 + 9 + 5*3 = 40

Candidate CC: 0 + 0 + 9 + 4 + 5*3 = 28

Candidate TC: 0 + 0 + 21 + 6 + 5*5 = 52

Candidate CF: 0 + 0 + 4 + 1 + 5*0 = 5

Candidate JG: 0 + 20 + 2 + 1 + 5*0 = 23

Candidate MH: 0 + 20 + 2 + 2 + 5*0 = 24

Candidate JK: 0 + 0 + 3 + 9 + 5*2 = 22

Candidate RP: 0 + 20 + 1 + 2 + 5*0 = 23

Candidate MR: 50 + 20 + 13 + 5 + 5*5 = 113

Candidate RS: 0 + 0 + 3 + 2 + 5*0 = 5

Candidate DT: 0 + 0 + 29 + 3 + 5*4 = 52

Testing suggestion:

Since the input for this problem is lengthy, I suggest creating a file containing the test data, and then using either cut-and-paste with the mouse or input redirection to run the test examples. This will save a considerable amount of typing.

1. Favorite-language problem

Write a program to solve the homework problem described above, using one of the following languages: Java, C, C++, or Python. (If you have another favorite language you'd prefer to use, talk to me.)

The input will contain the current state on a line by itself, then the number of candidates on a line by itself, then each candidate's information on a separate line. A candidate's information will be the five items listed in the general problem description (a 2-letter set of initials, a 2-letter state, and three integers), separated by spaces.

The output will be a list of candidates' names and scores, using the format illustrated in the examples below.

Examples:

Input:

NH

3

HC NY 78 21 1

MO MD 30 10 0

BS VT 93 15 0

Output:

HC 33

MO 13

BS 44

Input:

FL

12

JB FL 113 8 5

BC MD 163 9 3

CC NJ 95 4 3

TC TX 210 6 5

CF CA 40 1 0

JG VA 22 1 0

MH AR 25 2 0

JK OH 35 9 2

RP KY 13 2 0

MR FL 135 5 5

RS PA 38 2 0

DT NY 298 3 4

Output:

JB 94

BC 40

CC 28

TC 52

CF 5

JG 23

MH 24

JK 22

RP 22

MR 113

RS 5

DT 52

**Subject Computer Science C-Family Programming**