1 / 8

CompSci 6 Introduction to Computer Science

CompSci 6 Introduction to Computer Science. October 27, 2011 Prof. Rodger. Announcements. Read for next time Chap. 9.2-9.4 Reading Quiz on Blackboard Due before class next time Assignment 5 out tonight or tomorrow, due Nov 3 Today Apt – uniqueNames Problem – most popular name.

dodda
Download Presentation

CompSci 6 Introduction to Computer Science

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. CompSci 6Introduction to Computer Science October 27, 2011 Prof. Rodger

  2. Announcements • Read for next time Chap. 9.2-9.4 • Reading Quiz on Blackboard • Due before class next time • Assignment 5 out tonight or tomorrow, due Nov 3 • Today • Apt – uniqueNames • Problem – most popular name

  3. Popular Name Problem: • Given a list of names, determine the most popular first name and print that name with all of its last names. • Input: Names are always two words, names are in a file. If multiple names are on the same line they are separated by a “:” • Output: Most popular first name, followed by a “:”, followed by corresponding last names separated by a blank

  4. Example Input File with 5 lines Susan Smith:Jackie Long:Mary White Susan Brandt Jackie Johnson:Susan Rodger:Mary Rodger Eric Long:Susan Crackers:Mary Velios Jack Frost:Eric Lund Corresponding Output Susan: Smith Brandt Rodger Crackers

  5. One way to solve • Create a list of unique first names • Create a list of lists of last names that are associated with each first name

  6. Example – two lists Unique First names Corresponding Last names ’Susan’’ [ ‘Smith’,‘Brandt’,‘Rodger’,‘Crackers’]’ 1 1 ‘Jackie’ [ ‘Long’, ‘Johnson’]’ 2 2 ‘Mary’ [ ‘White’,’Rodger’,’Velios’]’ 3 3 [ ‘Long’, ‘Lund’]’ ‘Eric’ 4 4 ‘Jack’ [ ‘Frost’]’ 5 5

  7. Now can we solve the problem? • Compute those two lists that are associated with each other • List of unique first names • List of corresponding last names • Compute the max list of last names • Now easy to print the answer.

  8. Expanding the Problem • Suppose we want to read from multiple data files names1.txt, names2.txt, names3.txt

More Related