Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Code in java: Liam and Sathwika are enjoying being TAs for COP 3 5 0 3 , but they have decided to aim for higher

Code in java: Liam and Sathwika are enjoying being TAs for COP3503, but they have decided to aim for higher goals, like running for SGA President and Vice President. Unfortunately, they have realized that with tickets from the previous election such as Josh/Jad and Brad/Breon, they have no hope of winning because all winning tickets must have two distinct names that start with the same first letter, so Liam and Sathwika just won't do. Naturally, Liam was despondent about this revelation and to make himself feel better came up with a problem for all of the Computer Science 2 students. Given the names of each student at UCF, Liam wondered how many potential winning pairs for SGA President and Vice-President there might be. In order for a pair to have the potential to win, their names must be different but start with the same first letter. Since President and Vice President are different roles, we count the ticket of Josh and Jad differently than the ticket of Jad and Josh. (The first name listed is the candidate for President while the second name listed is the corresponding candidate for Vice President.) Note that UCF has many students that share a first name, so there might be several potential winning pairs of Josh and Jad. (For example, if there are 10 Joshes and 3 Jads on campus, there are 30 Josh/Jad pairs with a Josh running for President and a Jad running for Vice President.) The Problem: Given the names of each UCF student, calculate the number of possible President/Vice-President pairs who have a potential to win the SGA election. The Input: The first line of input contains a single positive integer, n (n <=105), representing the number of UCF students. The following n lines each contain a single first name of one UCF student. All names will consist of uppercase letters only and be between 1 and 20 letters long, inclusive. Each line represents a distinct student, but distinct students may have the same first name. The Output: On a line by itself, output the total number of President-Vice President pairs that have a chance to win the SGA election. Sample Input Sample Output 10 JOSH JAD JENNIFER JENNIFER JALEN HASAAN ALI TAMARA LIAM SATHWIKA 185 ALEX BRANDY CELINE DWAYNE ELIZABETH 0 Implementation Requirements This assignment is testing the use of Javas built in data structures. You must use at least one of the following in your code: HashSet, HashMap, TreeSet, TreeMap, PriorityQueue. The desired run time is O(n) expected run-time, where n is the number of input names. For full credit, a run-time of O(nlgn) must be achieved. As always, your code should use good style, including but not limited to: a header comment, reasonable number of internal comments, good modular break down, good variable names, utilizing objects and the Java API as appropriate for solving the problem.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Modern Database Management

Authors: Jeff Hoffer, Ramesh Venkataraman, Heikki Topi

13th Edition Global Edition

1292263350, 978-1292263359

More Books

Students also viewed these Databases questions

Question

In what context did the study and teaching of communication begin?

Answered: 1 week ago