cps6-111027Handout

cps6-111027Handout - One way to solve • Create a list of...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
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 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 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
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: 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 Example – two lists ’Susan’ ’ ‘Jackie’ ‘Jack’ ‘Eric’ ‘Mary’ [ ‘Smith’,‘Brandt’,‘Rodger’,‘Crackers’] ’ [ ‘Long’, ‘Johnson’] ’ [ ‘White’,’Rodger’,’Velios’] ’ [ ‘Long’, ‘Lund’] ’ [ ‘Frost’] ’ 1 2 3 4 5 1 2 3 4 5 Unique First names Corresponding Last names 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. Expanding the Problem • Suppose we want to read from multiple data files names1.txt, names2.txt, names3.txt...
View Full Document

{[ snackBarMessage ]}

Page1 / 2

cps6-111027Handout - One way to solve • Create a list of...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online